Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add phpdoc for constraint #42136

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

Closed
wants to merge 1 commit into from

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Jul 15, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#...

When extending some constraint and overriding some property, it's not always simple to know what can be passed to the properties and when it can be null. Those properties should have phpdoc to define their type.

Plus it avoid a psalm error NonInvariantDocblockPropertyType for the developer which use a more specific phpdoc (because atm, properties are considered as mixed).

And, it will help the typing for PHP8 on the branch 6.0 @nicolas-grekas :)

@derrabus
Copy link
Member

Fixing Doc blocks should be done as a bugfix on lower branches (4.4 mainly, in this case).

@VincentLanglet
Copy link
Contributor Author

Fixing Doc blocks should be done as a bugfix on lower branches (4.4 mainly, in this case).

I fully agree on this.
But on one of my last PR there was this debate #40604 and it ended with the decision it should be on 5.x.

If the core team now decide it's a bugfix, I'm fine doing it on 4.4 but I'd like some confirmation before doing this PR again.

@derrabus
Copy link
Member

Fair enough. Sorry for the confusion. 😞

@nicolas-grekas nicolas-grekas added this to the 5.4 milestone Jul 19, 2021
@nicolas-grekas
Copy link
Member

We try to remove phpdoc actually.
We have a rule where the default type of a property is enough clue to tell its type.
I'm fine adding phpdoc when it really brings value, but I'd better remove them otherwise.

@VincentLanglet
Copy link
Contributor Author

VincentLanglet commented Jul 19, 2021

We have a rule where the default type of a property is enough clue to tell its type.
I'm fine adding phpdoc when it really brings value, but I'd better remove them otherwise.

The rule has some sens, but it's not because a property has a default value that another type is forbidden
For instance
https://github.com/symfony/symfony/pull/42136/files#diff-738b9954d83ec3560d6a0b70f45958640c89abd268d72bba647e87c0ff13e185R50
The default value is an array, but looking at the code, a string is allowed too.

My main issue was that psalm and phpstan consider as mixed every property without typehint or phpdoc. Witch is pretty annoying when overriding a constraint class/property and adding some phpdoc. I would have prefer to add the phpdoc here rather than in the stub of psalm-symfony repository. The phpdoc can be removed in 6.0 when the type will be added.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 19, 2021

That's an issue with psalm/phpstan, it might be fixed with a plugin maybe?
But I'm overall 👎 to "pollute" the code base with useless phpdoc, we already spend too much time on maintaining these.

@VincentLanglet
Copy link
Contributor Author

That's an issue with psalm/phpstan, it might be fixed with a plugin maybe?
But I'm overall 👎 to "pollute" the code base with useless phpdoc, we already spend too much time on maintaining these.

So I should remove the phpdoc of property with default value and keep the others ?

@nicolas-grekas
Copy link
Member

So I should remove the phpdoc of property with default value and keep the others ?

That'd work for me yes. If a default value can be added instead in some cases, that'd be even better.

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.

4 participants