File tree Expand file tree Collapse file tree 9 files changed +188
-0
lines changed Expand file tree Collapse file tree 9 files changed +188
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ use function PHPStan \Testing \assertType ;
4
+
5
+ function (): void {
6
+ $ content = file_get_contents ('' );
7
+ if ($ content == '' ) {
8
+ die;
9
+ }
10
+
11
+ assertType ('string ' , $ content );
12
+ };
Original file line number Diff line number Diff line change @@ -1968,4 +1968,9 @@ public function testBug11418(): void
1968
1968
$ this ->analyse ([__DIR__ . '/data/bug-11418.php ' ], []);
1969
1969
}
1970
1970
1971
+ public function testBug3107 (): void
1972
+ {
1973
+ $ this ->analyse ([__DIR__ . '/data/bug-3107.php ' ], []);
1974
+ }
1975
+
1971
1976
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug3107 ;
4
+
5
+ class Holder
6
+ {
7
+ /** @var string */
8
+ public $ val ;
9
+ }
10
+
11
+ /** @param mixed $mixed */
12
+ function test ($ mixed ): void
13
+ {
14
+ $ holder = new Holder ();
15
+ $ holder ->val = $ mixed ;
16
+
17
+ $ a = [];
18
+ $ a [$ holder ->val ] = 1 ;
19
+ take ($ a );
20
+ }
21
+
22
+ /** @param array<string, int> $a */
23
+ function take ($ a ): void {}
Original file line number Diff line number Diff line change @@ -1171,4 +1171,50 @@ public function testShortGetPropertyHook(): void
1171
1171
]);
1172
1172
}
1173
1173
1174
+ public function testBug1O580 (): void
1175
+ {
1176
+ if (PHP_VERSION_ID < 80000 ) {
1177
+ $ this ->markTestSkipped ('Test requires PHP 8.0. ' );
1178
+ }
1179
+
1180
+ $ this ->analyse ([__DIR__ . '/data/bug-10580.php ' ], [
1181
+ [
1182
+ 'Method Bug10580\FooA::fooThisInterface() should return $this(Bug10580\FooA) but returns Bug10580\FooA. ' ,
1183
+ 18 ,
1184
+ ],
1185
+ [
1186
+ 'Method Bug10580\FooA::fooThisClass() should return $this(Bug10580\FooA) but returns Bug10580\FooA. ' ,
1187
+ 19 ,
1188
+ ],
1189
+ [
1190
+ 'Method Bug10580\FooA::fooThisSelf() should return $this(Bug10580\FooA) but returns Bug10580\FooA. ' ,
1191
+ 20 ,
1192
+ ],
1193
+ [
1194
+ 'Method Bug10580\FooA::fooThisStatic() should return $this(Bug10580\FooA) but returns Bug10580\FooA. ' ,
1195
+ 21 ,
1196
+ ],
1197
+ [
1198
+ 'Method Bug10580\FooB::fooThisInterface() should return $this(Bug10580\FooB) but returns Bug10580\FooB. ' ,
1199
+ 27 ,
1200
+ ],
1201
+ [
1202
+ 'Method Bug10580\FooB::fooThisClass() should return $this(Bug10580\FooB) but returns Bug10580\FooB. ' ,
1203
+ 29 ,
1204
+ ],
1205
+ [
1206
+ 'Method Bug10580\FooB::fooThisSelf() should return $this(Bug10580\FooB) but returns Bug10580\FooB. ' ,
1207
+ 31 ,
1208
+ ],
1209
+ [
1210
+ 'Method Bug10580\FooB::fooThisStatic() should return $this(Bug10580\FooB) but returns Bug10580\FooB. ' ,
1211
+ 33 ,
1212
+ ],
1213
+ [
1214
+ 'Method Bug10580\FooB::fooThis() should return $this(Bug10580\FooB) but returns Bug10580\FooB. ' ,
1215
+ 35 ,
1216
+ ],
1217
+ ]);
1218
+ }
1219
+
1174
1220
}
Original file line number Diff line number Diff line change
1
+ <?php // lint >= 8.0
2
+
3
+ namespace Bug10580 ;
4
+
5
+ interface FooI {
6
+ /** @return $this */
7
+ public function fooThisInterface (): FooI ;
8
+ /** @return $this */
9
+ public function fooThisClass (): FooI ;
10
+ /** @return $this */
11
+ public function fooThisSelf (): self ;
12
+ /** @return $this */
13
+ public function fooThisStatic (): static ;
14
+ }
15
+
16
+ final class FooA implements FooI
17
+ {
18
+ public function fooThisInterface (): FooI { return new FooA (); }
19
+ public function fooThisClass (): FooA { return new FooA (); }
20
+ public function fooThisSelf (): self { return new FooA (); }
21
+ public function fooThisStatic (): static { return new FooA (); }
22
+ }
23
+
24
+ final class FooB implements FooI
25
+ {
26
+ /** @return $this */
27
+ public function fooThisInterface (): FooI { return new FooB (); }
28
+ /** @return $this */
29
+ public function fooThisClass (): FooB { return new FooB (); }
30
+ /** @return $this */
31
+ public function fooThisSelf (): self { return new FooB (); }
32
+ /** @return $this */
33
+ public function fooThisStatic (): static { return new FooB (); }
34
+ /** @return $this */
35
+ public function fooThis (): static { return new FooB (); }
36
+ }
Original file line number Diff line number Diff line change @@ -95,4 +95,9 @@ public function testBug7310(): void
95
95
$ this ->analyse ([__DIR__ . '/data/bug-7310.php ' ], []);
96
96
}
97
97
98
+ public function testBug11939 (): void
99
+ {
100
+ $ this ->analyse ([__DIR__ . '/data/bug-11939.php ' ], []);
101
+ }
102
+
98
103
}
Original file line number Diff line number Diff line change
1
+ <?php // lint >= 8.1
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Bug11939 ;
6
+
7
+ enum What
8
+ {
9
+ case This;
10
+ case That;
11
+
12
+ /**
13
+ * @return ($this is self::This ? 'here' : 'there')
14
+ */
15
+ public function where (): string
16
+ {
17
+ return match ($ this ) {
18
+ self ::This => 'here ' ,
19
+ self ::That => 'there '
20
+ };
21
+ }
22
+ }
23
+
24
+ class Where
25
+ {
26
+ /**
27
+ * @return ($what is What::This ? 'here' : 'there')
28
+ */
29
+ public function __invoke (What $ what ): string
30
+ {
31
+ return match ($ what ) {
32
+ What::This => 'here ' ,
33
+ What::That => 'there '
34
+ };
35
+ }
36
+ }
Original file line number Diff line number Diff line change @@ -194,4 +194,10 @@ public function dataBug11207(): array
194
194
];
195
195
}
196
196
197
+ public function testBug12048 (): void
198
+ {
199
+ $ this ->treatPhpDocTypesAsCertain = true ;
200
+ $ this ->analyse ([__DIR__ . '/data/bug-12048.php ' ], []);
201
+ }
202
+
197
203
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug12048 ;
4
+
5
+ class HelloWorld
6
+ {
7
+ /** @phpstan-pure */
8
+ public function sayHello (string $ s ): string
9
+ {
10
+ $ a = md5 ( $ s );
11
+ $ a .= hash ( 'md5 ' , $ s );
12
+ $ a .= hash_hmac ( 'sha1 ' , $ s , 'b ' );
13
+
14
+ $ a .= hash ( 'sha256 ' , $ s );
15
+ $ a .= hash_hmac ( 'sha256 ' , $ s , 'b ' );
16
+
17
+ return $ a ;
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments