Support literals in ReturnTypeFromStrictTypedCallRector#4511
Support literals in ReturnTypeFromStrictTypedCallRector#4511TomasVotruba merged 4 commits intorectorphp:mainfrom
Conversation
|
I wonder how to make sure the strict type rules are idempotent, as we want to avoid one huge rule that handles all the script types everywhere. It was the case before and it was quite hard to handle and improve. Yet this looks good, thank you 👍 |
I agree that they are pretty close together and its not that easy to differentiate what is doing what. maybe we can find ways to combine existing rules which are "too similar" but still leave a line in-between - so some separation is still happing instead of a big ball of mud. |
|
from a end-user point of view, I like those separate rector rules though, since it allows to refactor big code-bases in portions. if we had less rules which do more stuff, it could lead to tooo big PRs on legacy projecs which are hard to review. |
before this PR
ReturnTypeFromStrictTypedCallRectorgave up adding return types, as soon as a single return was contained which cannot be resolved to the same type as others.after this PR we also take returns into account which contain literal values, e.g.
return 1;.this allows in the following example to infer the type, which we couldn't without the patch:
final class SameTypedArrayReturns { - public function getData() + public function getData(): array { if (rand(0,1)) { return []; // this path made the previous implementation give up adding a type } return $this->getArray(); } public function getArray(): array { } }