Content-Length: 484315 | pFad | http://github.com/symfony/symfony/pull/59540

6B [PropertyInfo] Get short description from promoted properties in PhpDocExtractor by wuchen90 · Pull Request #59540 · symfony/symfony · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PropertyInfo] Get short description from promoted properties in PhpDocExtractor #59540

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

wuchen90
Copy link
Contributor

@wuchen90 wuchen90 commented Jan 17, 2025

Q A
Branch? 6.4
Bug fix? yes
License MIT

Currently this kind of phpdoc doesn't work to get description:

class Foo {
  /**
   * @param mixed $foo This description can't be get by PhpDocExtractor
   */
  public function __construct(
    public $foo,
  ) {}
}

Whereas this one works:

class Foo {
  public function __construct(
    /** @var mixed $foo This description can be get by PhpDocExtractor */
    public $foo,
  ) {}
}

@OskarStark
Copy link
Contributor

This is a feature and should target 7.3

@OskarStark OskarStark modified the milestones: 6.4, 7.3 Jan 17, 2025
@wuchen90
Copy link
Contributor Author

wuchen90 commented Jan 17, 2025

@OskarStark

This is a feature and should target 7.3

I don't know if this is really a feature because it works well with @var annotation.
Only, when we document a method, we usually use @param and not @var.

Beside, this code below points out that we support promoted properties:

case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($class, $property):

Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the changelog as well, as it's a feature?

@@ -95,6 +95,18 @@ public function getShortDescription(string $class, string $property, array $cont
}
}

foreach ($docBlock->getTagsByName('param') as $param) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update PhpStanExtractor as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've looked at it and it seems it needs more work for PhpStanExtractor than what I've done here.
So I propose to do it in another PR.


$paramDescription = $param->getDescription()?->render();

if (null !== $paramDescription && '' !== $paramDescription) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (null !== $paramDescription && '' !== $paramDescription) {
if ($paramDescription) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure?

<?php
$paramDescription = '0';

echo $paramDescription ? 'ok' : 'ko'; // 'ko'

echo null !== $paramDescription && '' !== $paramDescription ? 'ok' : 'ko'; // 'ok'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure 0 a useful description either

Copy link
Contributor Author

@wuchen90 wuchen90 Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimming 0 won't make it less predictable?
I mean in the way that, from the user point of view, we naturally expect that empty string or null can be skipped.
But other than these two cases, shouldn't we return what the user has input or is it what Symfony used to do for this kind of code?
If we skip 0 then I should add a test for it.

@OskarStark
Copy link
Contributor

Looking at your code change this seems like it wasn't implemented before, there is no wrong behavior, the feature is just not existent, so a feature to me.

@stof
Copy link
Member

stof commented Jan 17, 2025

I think the implementation would now read @param in docblock of any properties, not just for the case of reading the constructor docblock for a promoted property.

Copy link
Contributor Author

@wuchen90 wuchen90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target branch changed to 7.3.

@@ -95,6 +95,18 @@ public function getShortDescription(string $class, string $property, array $cont
}
}

foreach ($docBlock->getTagsByName('param') as $param) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've looked at it and it seems it needs more work for PhpStanExtractor than what I've done here.
So I propose to do it in another PR.


$paramDescription = $param->getDescription()?->render();

if (null !== $paramDescription && '' !== $paramDescription) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure?

<?php
$paramDescription = '0';

echo $paramDescription ? 'ok' : 'ko'; // 'ko'

echo null !== $paramDescription && '' !== $paramDescription ? 'ok' : 'ko'; // 'ok'

@mtarld
Copy link
Contributor

mtarld commented Jan 20, 2025

Indeed, forgot about it, you can keep null !== $paramDescription && '' !== $paramDescription then 🙂


$paramDescription = $param->getDescription()?->render();

if (null !== $paramDescription && '' !== $paramDescription) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure 0 a useful description either

@wuchen90 wuchen90 force-pushed the fix-phpdoc-extractor branch from f6c61c1 to 9141b68 Compare January 31, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/symfony/symfony/pull/59540

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy