File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed
tests/PHPStan/Rules/Comparison Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -1085,4 +1085,16 @@ public function testBug9666(): void
10851085 ]);
10861086 }
10871087
1088+ public function testBug9445 (): void
1089+ {
1090+ $ this ->treatPhpDocTypesAsCertain = true ;
1091+ $ this ->analyse ([__DIR__ . '/data/bug-9445.php ' ], []);
1092+ }
1093+
1094+ public function testBug7773 (): void
1095+ {
1096+ $ this ->treatPhpDocTypesAsCertain = true ;
1097+ $ this ->analyse ([__DIR__ . '/data/bug-7773.php ' ], []);
1098+ }
1099+
10881100}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Bug7773 ;
4+
5+ class JSONEncodingException extends \Exception
6+ {
7+ }
8+
9+ class JSONDecodingException extends \Exception
10+ {
11+ }
12+
13+ class HelloWorld
14+ {
15+ /**
16+ * Encodes the data as JSON
17+ * @param array<mixed> $data json array
18+ * @return string json string
19+ * @throws JSONEncodingException
20+ */
21+ public static function JSONEncode (array $ data ): string
22+ {
23+ if (!is_string ($ data = json_encode ($ data )))
24+ throw new JSONEncodingException ();
25+ return $ data ;
26+ }
27+
28+ /**
29+ * Decodes the JSON data as an array
30+ * @param string $data json string
31+ * @return array<mixed> json array
32+ * @throws JSONDecodingException
33+ */
34+ public static function JSONDecode (string $ data ): array
35+ {
36+ if (!is_array ($ data = json_decode ($ data , true )))
37+ throw new JSONDecodingException ();
38+ return $ data ;
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Bug9445 ;
4+
5+ class Foo
6+ {
7+ public int $ id ;
8+ public null |self $ parent ;
9+
10+ public function contains (self $ foo ): bool
11+ {
12+ do {
13+ if ($ this ->id === $ foo ->id ) {
14+ return true ;
15+ }
16+ } while (!is_null ($ foo = $ foo ->parent ));
17+
18+ return false ;
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments