VarTagTypeRuleHelper: remove all useless/wrong complexity#2805
VarTagTypeRuleHelper: remove all useless/wrong complexity#2805janedbal wants to merge 2 commits intophpstan:1.10.xfrom
Conversation
| [ | ||
| 'PHPDoc tag @var with type array is not subtype of native type array{}.', | ||
| 29, | ||
| ], |
There was a problem hiding this comment.
All constant assignments are working fine. Those is imo invalid "init variable" approaches and should be reported.
But, this is probably solvable in shouldVarTagTypeBeReported if you really insist on previous behaviour.
|
The complexity is there precisely because I want to allow: /** @var int[] $foo */
$foo = returnListOfIntegers();Because it's harmless and PHPStan cannot be too annoying. After one of your changes (#2738) I had to spend some time iterating so that the rule isn't too annoying: As it stands right now when someone comes to me with a question regarding "PHPStan complains about my After #2738 I found situations in real-world code that I myself didn't know how to solve (aside from deleting Inline |
|
I believe there should be some option to have it strictly based on type system, not based on your taste. This way (with all this complexity), there will be many more holes - just found another issue ( Also, allowing list to array widening may seem ok-ish for one, but we utilize lists a lot and this is degrading our efforts. All those holes are hard to spot, I invested quite some time to find all those I reported (1, 2, 3, 4). But if you insist keeping this as-is, I can always add the strict & proper behaviour to https://github.com/shipmonk-rnd/phpstan-rules Last thing to consider: maybe if there was some way to do "declare variable type" in PHPStan (like some |
|
An idea: |
|
Not really a fan of that idea. I think people are used to that
are almost synonyms. With some exceptions in IDEs. |
|
@ondrejmirtes What about feature flag |
|
@janedbal Feature flags are for things we eventually want to enable for everybody (in the next major version). Which already applies to this rule (it's only in bleeding edge). But I don't want this proposed behaviour in the next major version. |
|
If you mean a new permanent option like listed here https://phpstan.org/config-reference#stricter-analysis, then sure, I'd merge that, there's already |
|
Yeah, I mean regular option. Thx, I'll prepare that. |
|
I suggest to name it - reportWrongPhpDocTypeInVarTag: true
- stricterPhpDocTypeCheckInVarTag: true |
This is a better version of #2804, adding more and more conditions for edgecases will always leave rooms for errors. Lets keep it simple & correct.
Maybe we can enable this strict & proper behaviour only for bleedingEdge?