Implement @phpstan-consistent-constructor#1296
Conversation
f1abb37 to
f5415d5
Compare
ondrejmirtes
left a comment
There was a problem hiding this comment.
This is almost perfect :) I think I'd like to see some edge cases handled. I think that @phpstan-consistent-constructor should be allowed above a class that doesn't have constructor at all.
Please add a test that it's possible to extend such class and that: 1) missing constructor in a subclass is not reported, 2) subclass can have a constructor with no parameters (optional parameters also allowed, 3) subclass cannot have a constructor with required parameters.
|
And also, please open a PR in https://github.com/phpstan/phpstan that updates this blogpost :) https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static Thanks |
|
Added the test cases. And yeah, this case was not covered, so fixed it. |
|
Thank you! |
This PR adds a new tag called
@phpstan-consistent-constructorand a rule to enforce it.I wasn't sure which level this rule should be in, so for now I added it to level 0. But I can change it to correct one.
There are not many test cases because same things are covered by
OverridingMethodRuletests. I only tested relevant stuff for this rule. But of course I can add more test cases, if there is an edge case we need to cover.