5
5
use PHPStan \Reflection \ClassReflection ;
6
6
use PHPStan \Reflection \ReflectionProviderStaticAccessor ;
7
7
use PHPStan \TrinaryLogic ;
8
+ use function get_class ;
8
9
use function sprintf ;
9
10
10
11
/** @api */
@@ -23,9 +24,36 @@ public function __construct(
23
24
parent ::__construct ($ classReflection , $ subtractedType );
24
25
}
25
26
27
+ public function equals (Type $ type ): bool
28
+ {
29
+ if (get_class ($ type ) !== static ::class) {
30
+ return false ;
31
+ }
32
+
33
+ /** @var ThisType $type */
34
+ $ type = $ type ;
35
+ $ equals = $ this ->getStaticObjectType ()->equals ($ type ->getStaticObjectType ());
36
+ if (!$ equals ) {
37
+ return false ;
38
+ }
39
+
40
+ if ($ this ->getTraitReflection () === null ) {
41
+ if ($ type ->getTraitReflection () === null ) {
42
+ return true ;
43
+ }
44
+
45
+ return false ;
46
+ }
47
+ if ($ type ->getTraitReflection () === null ) {
48
+ return false ;
49
+ }
50
+
51
+ return $ this ->getTraitReflection ()->getName () === $ type ->getTraitReflection ()->getName ();
52
+ }
53
+
26
54
public function changeBaseClass (ClassReflection $ classReflection ): StaticType
27
55
{
28
- return new self ($ classReflection , $ this ->getSubtractedType ());
56
+ return new self ($ classReflection , $ this ->getSubtractedType (), $ this -> traitReflection );
29
57
}
30
58
31
59
public function describe (VerbosityLevel $ level ): string
@@ -50,6 +78,10 @@ function () use ($callback): string {
50
78
public function isSuperTypeOf (Type $ type ): TrinaryLogic
51
79
{
52
80
if ($ type instanceof self) {
81
+ if ($ this ->equals ($ type )) {
82
+ return TrinaryLogic::createYes ();
83
+ }
84
+
53
85
return $ this ->getStaticObjectType ()->isSuperTypeOf ($ type );
54
86
}
55
87
@@ -66,7 +98,7 @@ public function changeSubtractedType(?Type $subtractedType): Type
66
98
{
67
99
$ type = parent ::changeSubtractedType ($ subtractedType );
68
100
if ($ type instanceof parent) {
69
- return new self ($ type ->getClassReflection (), $ subtractedType );
101
+ return new self ($ type ->getClassReflection (), $ subtractedType, $ this -> traitReflection );
70
102
}
71
103
72
104
return $ type ;
@@ -93,6 +125,7 @@ public function traverse(callable $cb): Type
93
125
return new self (
94
126
$ this ->getClassReflection (),
95
127
$ subtractedType ,
128
+ $ this ->traitReflection ,
96
129
);
97
130
}
98
131
0 commit comments