5
5
use PHPStan \Reflection \ClassReflection ;
6
6
use PHPStan \Reflection \ReflectionProviderStaticAccessor ;
7
7
use PHPStan \TrinaryLogic ;
8
- use function get_class ;
9
8
use function sprintf ;
10
9
11
10
/** @api */
@@ -18,70 +17,24 @@ class ThisType extends StaticType
18
17
public function __construct (
19
18
ClassReflection $ classReflection ,
20
19
?Type $ subtractedType = null ,
21
- private ?ClassReflection $ traitReflection = null ,
22
20
)
23
21
{
24
22
parent ::__construct ($ classReflection , $ subtractedType );
25
23
}
26
24
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
-
54
25
public function changeBaseClass (ClassReflection $ classReflection ): StaticType
55
26
{
56
- return new self ($ classReflection , $ this ->getSubtractedType (), $ this -> traitReflection );
27
+ return new self ($ classReflection , $ this ->getSubtractedType ());
57
28
}
58
29
59
30
public function describe (VerbosityLevel $ level ): string
60
31
{
61
- $ callback = fn () => sprintf ('$this(%s) ' , $ this ->getStaticObjectType ()->describe ($ level ));
62
- return $ level ->handle (
63
- $ callback ,
64
- $ callback ,
65
- $ callback ,
66
- function () use ($ callback ): string {
67
- $ base = $ callback ();
68
- $ trait = $ this ->getTraitReflection ();
69
- if ($ trait === null ) {
70
- return $ base ;
71
- }
72
-
73
- return sprintf ('%s-trait-%s ' , $ base , $ trait ->getDisplayName ());
74
- },
75
- );
32
+ return sprintf ('$this(%s) ' , $ this ->getStaticObjectType ()->describe ($ level ));
76
33
}
77
34
78
35
public function isSuperTypeOf (Type $ type ): TrinaryLogic
79
36
{
80
37
if ($ type instanceof self) {
81
- if ($ this ->equals ($ type )) {
82
- return TrinaryLogic::createYes ();
83
- }
84
-
85
38
return $ this ->getStaticObjectType ()->isSuperTypeOf ($ type );
86
39
}
87
40
@@ -98,25 +51,12 @@ public function changeSubtractedType(?Type $subtractedType): Type
98
51
{
99
52
$ type = parent ::changeSubtractedType ($ subtractedType );
100
53
if ($ type instanceof parent) {
101
- return new self ($ type ->getClassReflection (), $ subtractedType, $ this -> traitReflection );
54
+ return new self ($ type ->getClassReflection (), $ subtractedType );
102
55
}
103
56
104
57
return $ type ;
105
58
}
106
59
107
- /**
108
- * @phpstan-assert-if-true !null $this->getTraitReflection()
109
- */
110
- public function isInTrait (): bool
111
- {
112
- return $ this ->traitReflection !== null ;
113
- }
114
-
115
- public function getTraitReflection (): ?ClassReflection
116
- {
117
- return $ this ->traitReflection ;
118
- }
119
-
120
60
public function traverse (callable $ cb ): Type
121
61
{
122
62
$ subtractedType = $ this ->getSubtractedType () !== null ? $ cb ($ this ->getSubtractedType ()) : null ;
@@ -125,7 +65,6 @@ public function traverse(callable $cb): Type
125
65
return new self (
126
66
$ this ->getClassReflection (),
127
67
$ subtractedType ,
128
- $ this ->traitReflection ,
129
68
);
130
69
}
131
70
0 commit comments