Skip to content

Commit fd645ff

Browse files
authored
Merge branch refs/heads/1.12.x into 2.1.x
2 parents 0b4e510 + abbae6a commit fd645ff

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,4 +961,18 @@ public function testBug3979(): void
961961
$this->analyse([__DIR__ . '/data/bug-3979.php'], []);
962962
}
963963

964+
public function testBug8464(): void
965+
{
966+
$this->checkAlwaysTrueCheckTypeFunctionCall = true;
967+
$this->treatPhpDocTypesAsCertain = true;
968+
$this->analyse([__DIR__ . '/data/bug-8464.php'], []);
969+
}
970+
971+
public function testBug8954(): void
972+
{
973+
$this->checkAlwaysTrueCheckTypeFunctionCall = true;
974+
$this->treatPhpDocTypesAsCertain = true;
975+
$this->analyse([__DIR__ . '/data/bug-8954.php'], []);
976+
}
977+
964978
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)