File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
tests/PHPStan/Analyser/data Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 10
10
use PHPStan \TrinaryLogic ;
11
11
use PHPStan \Type \Generic \TemplateTypeMap ;
12
12
use PHPStan \Type \MixedType ;
13
+ use PHPStan \Type \ThisType ;
13
14
use PHPStan \Type \Type ;
14
15
15
16
class AnnotationMethodReflection implements ExtendedMethodReflection
@@ -122,6 +123,10 @@ public function hasSideEffects(): TrinaryLogic
122
123
return TrinaryLogic::createYes ();
123
124
}
124
125
126
+ if ((new ThisType ($ this ->declaringClass ))->isSuperTypeOf ($ this ->returnType )->yes ()) {
127
+ return TrinaryLogic::createYes ();
128
+ }
129
+
125
130
return TrinaryLogic::createMaybe ();
126
131
}
127
132
Original file line number Diff line number Diff line change 30
30
use PHPStan \Type \MixedType ;
31
31
use PHPStan \Type \ObjectWithoutClassType ;
32
32
use PHPStan \Type \StringType ;
33
+ use PHPStan \Type \ThisType ;
33
34
use PHPStan \Type \Type ;
34
35
use PHPStan \Type \TypehintHelper ;
35
36
use PHPStan \Type \VoidType ;
@@ -430,6 +431,10 @@ public function hasSideEffects(): TrinaryLogic
430
431
return TrinaryLogic::createFromBoolean (!$ this ->isPure );
431
432
}
432
433
434
+ if ((new ThisType ($ this ->declaringClass ))->isSuperTypeOf ($ this ->getReturnType ())->yes ()) {
435
+ return TrinaryLogic::createYes ();
436
+ }
437
+
433
438
return TrinaryLogic::createMaybe ();
434
439
}
435
440
Original file line number Diff line number Diff line change 4
4
5
5
use function PHPStan \Testing \assertType ;
6
6
7
+ /**
8
+ * @method $this phpDocReturnThis()
9
+ */
7
10
class Foo
8
11
{
9
12
@@ -15,6 +18,14 @@ public function voidMethod(): void
15
18
$ this ->fooProp = rand (0 , 1 );
16
19
}
17
20
21
+ /**
22
+ * @return $this
23
+ */
24
+ public function returnsThis ()
25
+ {
26
+ $ this ->fooProp = rand (0 , 1 );
27
+ }
28
+
18
29
public function ordinaryMethod (): int
19
30
{
20
31
return 1 ;
@@ -51,6 +62,24 @@ public function doFoo(): void
51
62
assertType ('int ' , $ this ->fooProp );
52
63
}
53
64
65
+ public function doFluent (): void
66
+ {
67
+ $ this ->fooProp = 1 ;
68
+ assertType ('1 ' , $ this ->fooProp );
69
+
70
+ $ this ->returnsThis ();
71
+ assertType ('int ' , $ this ->fooProp );
72
+ }
73
+
74
+ public function doFluent2 (): void
75
+ {
76
+ $ this ->fooProp = 1 ;
77
+ assertType ('1 ' , $ this ->fooProp );
78
+
79
+ $ this ->phpDocReturnThis ();
80
+ assertType ('int ' , $ this ->fooProp );
81
+ }
82
+
54
83
public function doBar (): void
55
84
{
56
85
$ this ->fooProp = 1 ;
You can’t perform that action at this time.
0 commit comments