File tree Expand file tree Collapse file tree
rules-tests/Php74/Rector/Property/TypedPropertyRector/FixtureClassLikeTypeOnly Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Php74 \Rector \Property \TypedPropertyRector \FixtureClassLikeTypeOnly ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Prophecy \Prophecy \ObjectProphecy ;
7+ use Prophecy \PhpUnit \ProphecyTrait ;
8+ use Rector \Tests \Php74 \Rector \Property \TypedPropertyRector \Source \ReturnString ;
9+
10+ class ReturnStringTest extends TestCase
11+ {
12+ use ProphecyTrait;
13+
14+ /**
15+ * @var ReturnString|ObjectProphecy
16+ */
17+ private $ obj ;
18+
19+ protected function setUp (): void
20+ {
21+ $ this ->obj = $ this ->prophesize (ReturnString::class);
22+ }
23+
24+ public function testReturnName ()
25+ {
26+ $ this ->obj ->getName ()->willReturn ('name ' )->shouldBeCalled ();
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Php74 \Rector \Property \TypedPropertyRector \FixtureClassLikeTypeOnly ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Prophecy \Prophecy \ObjectProphecy ;
7+ use Prophecy \PhpUnit \ProphecyTrait ;
8+ use Rector \Tests \Php74 \Rector \Property \TypedPropertyRector \Source \ReturnString ;
9+
10+ class ReturnString2Test extends TestCase
11+ {
12+ use ProphecyTrait;
13+
14+ /**
15+ * @var ReturnString|ObjectProphecy
16+ */
17+ private $ obj = null ;
18+
19+ protected function setUp (): void
20+ {
21+ $ this ->obj = $ this ->prophesize (ReturnString::class);
22+ }
23+
24+ public function testReturnName ()
25+ {
26+ $ this ->obj ->getName ()->willReturn ('name ' )->shouldBeCalled ();
27+ }
28+ }
Original file line number Diff line number Diff line change 2727use Rector \DeadCode \PhpDoc \TagRemover \VarTagRemover ;
2828use Rector \FamilyTree \Reflection \FamilyRelationsAnalyzer ;
2929use Rector \NodeTypeResolver \Node \AttributeKey ;
30+ use Rector \Php74 \TypeAnalyzer \ObjectTypeAnalyzer ;
3031use Rector \Php74 \TypeAnalyzer \PropertyUnionTypeResolver ;
3132use Rector \PHPStanStaticTypeMapper \DoctrineTypeAnalyzer ;
3233use Rector \PHPStanStaticTypeMapper \Enum \TypeKind ;
3334use Rector \StaticTypeMapper \ValueObject \Type \AliasedObjectType ;
34- use Rector \StaticTypeMapper \ValueObject \Type \NonExistingObjectType ;
3535use Rector \TypeDeclaration \TypeInferer \PropertyTypeInferer ;
3636use Rector \VendorLocker \VendorLockResolver ;
3737use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
@@ -81,6 +81,7 @@ public function __construct(
8181 private PropertyAnalyzer $ propertyAnalyzer ,
8282 private PropertyUnionTypeResolver $ propertyUnionTypeResolver ,
8383 private AstResolver $ astResolver ,
84+ private ObjectTypeAnalyzer $ objectTypeAnalyzer
8485 ) {
8586 }
8687
@@ -153,8 +154,7 @@ public function refactor(Node $node): ?Node
153154 }
154155 }
155156
156- // we are not sure what object type this is
157- if ($ varType instanceof NonExistingObjectType) {
157+ if ($ this ->objectTypeAnalyzer ->isSpecial ($ varType )) {
158158 return null ;
159159 }
160160
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Php74 \TypeAnalyzer ;
6+
7+ use PHPStan \Type \Type ;
8+ use PHPStan \Type \UnionType ;
9+ use Rector \StaticTypeMapper \ValueObject \Type \FullyQualifiedObjectType ;
10+ use Rector \StaticTypeMapper \ValueObject \Type \NonExistingObjectType ;
11+
12+ final class ObjectTypeAnalyzer
13+ {
14+ public function isSpecial (Type $ varType ): bool
15+ {
16+ // we are not sure what object type this is
17+ if ($ varType instanceof NonExistingObjectType) {
18+ return true ;
19+ }
20+
21+ $ types = ! $ varType instanceof UnionType
22+ ? [$ varType ]
23+ : $ varType ->getTypes ();
24+
25+ foreach ($ types as $ type ) {
26+ if ($ type instanceof FullyQualifiedObjectType && $ type ->getClassName () === 'Prophecy\Prophecy\ObjectProphecy ' ) {
27+ return true ;
28+ }
29+ }
30+
31+ return false ;
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments