File tree 3 files changed +64
-0
lines changed
tests/PHPStan/Rules/Comparison
3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -1109,4 +1109,22 @@ public function testBug3979(): void
1109
1109
$ this ->analyse ([__DIR__ . '/data/bug-3979.php ' ], []);
1110
1110
}
1111
1111
1112
+ public function testBug8464 (): void
1113
+ {
1114
+ if (PHP_VERSION_ID < 80000 ) {
1115
+ $ this ->markTestSkipped ('Test requires PHP 8.0. ' );
1116
+ }
1117
+
1118
+ $ this ->checkAlwaysTrueCheckTypeFunctionCall = true ;
1119
+ $ this ->treatPhpDocTypesAsCertain = true ;
1120
+ $ this ->analyse ([__DIR__ . '/data/bug-8464.php ' ], []);
1121
+ }
1122
+
1123
+ public function testBug8954 (): void
1124
+ {
1125
+ $ this ->checkAlwaysTrueCheckTypeFunctionCall = true ;
1126
+ $ this ->treatPhpDocTypesAsCertain = true ;
1127
+ $ this ->analyse ([__DIR__ . '/data/bug-8954.php ' ], []);
1128
+ }
1129
+
1112
1130
}
Original file line number Diff line number Diff line change
1
+ <?php // lint >= 8.0
2
+
3
+ namespace Bug8464 ;
4
+
5
+ final class ObjectUtil
6
+ {
7
+ /**
8
+ * @param class-string $type
9
+ */
10
+ public static function instanceOf (mixed $ object , string $ type ): bool
11
+ {
12
+ return \is_object ($ object )
13
+ && (
14
+ $ object ::class === $ type ||
15
+ is_subclass_of ($ object , $ type )
16
+ );
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace Bug8954 ;
4
+
5
+ /**
6
+ * @template U
7
+ * @template V
8
+ *
9
+ * @param ?class-string<U> $class
10
+ * @param class-string<V> $expected
11
+ *
12
+ * @return ?class-string<V>
13
+ */
14
+ function ensureSubclassOf (?string $ class , string $ expected ): ?string {
15
+ if ($ class === null ) {
16
+ return $ class ;
17
+ }
18
+
19
+ if (!class_exists ($ class )) {
20
+ throw new \Exception ("Class “ {$ class }” does not exist. " );
21
+ }
22
+
23
+ if (!is_subclass_of ($ class , $ expected )) {
24
+ throw new \Exception ("Class “ {$ class }” is not a subclass of “ {$ expected }”. " );
25
+ }
26
+
27
+ return $ class ;
28
+ }
You can’t perform that action at this time.
0 commit comments