Skip to content

Commit d814e38

Browse files
committed
Add rule test for get_parent_class($this) === self::class not being always false
Covers the reported identical.alwaysFalse false positive at the rule level, in addition to the type-inference assertions.
1 parent 939aa1f commit d814e38

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ public function testBug2835(): void
347347
$this->analyse([__DIR__ . '/data/bug-2835.php'], []);
348348
}
349349

350+
public function testBug14951(): void
351+
{
352+
$this->analyse([__DIR__ . '/data/bug-14951.php'], []);
353+
}
354+
350355
public function testBug1860(): void
351356
{
352357
$this->analyse([__DIR__ . '/data/bug-1860.php'], [
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14951StrictComparison;
4+
5+
class A
6+
{
7+
8+
public function isDirectChildOfA(): bool
9+
{
10+
// $this can be an instance of a subclass, so get_parent_class($this)
11+
// can equal self::class for a direct child — this comparison is not always false.
12+
return get_parent_class($this) === self::class;
13+
}
14+
15+
}
16+
17+
class B extends A
18+
{
19+
}
20+
21+
class C extends B
22+
{
23+
}

0 commit comments

Comments
 (0)