[DX] Remove *AnnotationIncorrectNullableRector rules as works with unreliable docblocks and can have 2 solutions#4719
Conversation
…liable docblocks and can have 2 solutions
167b810 to
e2dfa39
Compare
| /** | ||
| * @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamAnnotationIncorrectNullableRector\ParamAnnotationIncorrectNullableRectorTest | ||
| */ | ||
| final class ParamAnnotationIncorrectNullableRector extends AbstractRector implements MinPhpVersionInterface |
There was a problem hiding this comment.
There are 3 rules that fix incorrect nullable:
ReturnAnnotationIncorrectNullableRector
ParamAnnotationIncorrectNullableRector
VarAnnotationIncorrectNullableRector
There was a problem hiding this comment.
I see, I'll add them to this removal list 👍 Thanks
There was a problem hiding this comment.
actually, I can see these rules are actually good, this example verify based on typed existing param, eg:
/**
- * @param \DateTime[] $dateTimes
+ * @param \DateTime[]|null $dateTimes
*/
public function setDateTimes(?array $dateTimes): self|
/cc @dorrogeray FYI |
…changes, better decide with PHPStan
…nges, better decide with PHPStan
|
@TomasVotruba actually, I can see these rules are actually good, this example verify based on typed existing param, eg: /**
- * @param \DateTime[] $dateTimes
+ * @param \DateTime[]|null $dateTimes
*/
public function setDateTimes(?array $dateTimes): selfprobably you can reconsider it? |
|
I was thinking about the usefulness and they can preserve the state like example. The question is, often the nullability is not desired and code should be changed differently: /**
* @param \DateTime[] $dateTimes
*/
- public function setDateTimes(?array $dateTimes): self
+ public function setDateTimes(array $dateTimes): selfSame applies for var/return cases. Instead of silently preserving wrong state, it should be handled by developer to fits exact needs. That's why I think it's better let PHPStan report these and people to decide what way should be taken. |
These rules work with unreliable docblocks and can have 2 solutions.
Since Rector 0.15 we declare type stricness and avoid docblock changes, as unreliable and could lead to incorrect assumptions: https://getrector.com/blog/new-in-rector-015-complete-safe-and-known-type-declarations
These are one of few forgotten rules. Instead handle manually and let PHPStan help you decide 👍