[Php74] Skip ObjectProphecy type on TypedPropertyRector#1358
Conversation
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
be81712 to
fcfb271
Compare
| if ($this->objectTypeAnalyzer->isSpecial($varType)) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Here should be check for PHP version and IntersectionType or UnionType instead.
E.g. the fixture above should work on PHP 8.1 as it's intersection type.
There was a problem hiding this comment.
it is not about usage of UnionType, it is about usage of ObjectProphecy in types found, can be UnionType when has null default value, if no default value, it will be object type of ObjectProphecy
There was a problem hiding this comment.
On php 8.x feature enabled, without this check, it will produce this for UnionType nullable:
- private $obj = null;
+ private ?\Prophecy\Prophecy\ObjectProphecy $obj = null;or object type:
- private $obj;
+ private \Prophecy\Prophecy\ObjectProphecy $obj;which incorrect, as it need to be special:
/** @var ReturnString|ObjectProphecy */as original issue described at rectorphp/rector#6843
There was a problem hiding this comment.
The type should be ReturnString|ObjectProphecy. Somewhere we loose the ReturnString type.
This is correct result:
private ReturnString|ObjectProphecy|null $obj = null;As a bonus, type might be contextually resolved as never-null, since the setUp() method is always run in PHPUnit test.
There was a problem hiding this comment.
That maybe because of it uses the $this->prophesize() call return type so it goes to ObjectProphecy type. I will check if it can fallback to the type based on the @var if it has ObjectProphecy type.
There was a problem hiding this comment.
I see, that might be difficult to resolve with incorrect 3rd party doc types. Let's go with current solution then 👍
closes rectorphp/rector#6843