phpstan / phpdoc-parser

Next-gen phpDoc parser with support for intersection types and generics
MIT License
1.36k stars 61 forks source link

Add support for `@property $foo` syntax. #239

Closed VincentLanglet closed 6 months ago

VincentLanglet commented 6 months ago

Hi @ondrejmirtes,

Currently the parser correctly parse

@property mixed $foo

but fail on

@property $foo

for instance https://phpstan.org/r/2534dcd1-fb4e-47af-80f2-1d2f896ec6aa

This is a syntax used by at least the following lib https://github.com/gocardless/gocardless-pro-php/blob/882efd66430b6dec9baeceb2ea6bb7078c3ef908/lib/Resources/Block.php#L14.

And I would say that since we can write

@method doThings($foo)

or to define a property without a type

private $foo

it could make sens to allow

@property $foo

Would you open to support such syntax and allowing type to be nullable in PropertyTagValueNode ?

ondrejmirtes commented 6 months ago

I disagree. Libs should follow what's already supported in the world, not invent new syntax and hope for the best.

VincentLanglet commented 6 months ago

I disagree. Libs should follow what's already supported in the world, not invent new syntax and hope for the best.

I understand the point of view and agree with it but I made search and I think the syntax is valid, according to Phpdocumentor, https://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.property.pkg.html

It says

phpDocumentor will display the optional description unmodified, and defaults to "mixed" if the datatype is not present.

So it seems allowed that the "datatype is not present".

ondrejmirtes commented 6 months ago

I don't think that something written 17 years ago is relevant here.

VincentLanglet commented 6 months ago

I don't think that something written 17 years ago is relevant here.

Sure.

So I just

So the syntax still seems to be a valid one in 2024.

VincentLanglet commented 6 months ago

The syntax is also supported by PHPStorm

image

Libs should follow what's already supported in the world, not invent new syntax and hope for the best.

My point is that it's not easy to ask a lib to change his syntax when the "only" tools (phpdocumentor/phpstorm) there are using are supporting the syntax. And it would be helpful to not having to write stubs for every classes of this lib. I'm ok doing all the PR needed for this support.

ondrejmirtes commented 6 months ago

Sorry, I'm not going to add this and I'm locking this thread. phpdoc-parser has been introduced to PHPStan 6.5 years ago and no one up until now asked for this which means this isn't really an issue.

@property without a type makes the code worse. I want to make the PHP ecosysytem better not by allowing @property without a type, but by forcing people to add the type instead.