Skip to content

Commit

Permalink
Anonymous classes are final
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 2, 2022
1 parent 42a9252 commit a418c46
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,10 @@ public function hasConsistentConstructor(): bool

public function isFinalByKeyword(): bool
{
if ($this->isAnonymous()) {
return true;
}

return $this->reflection->isFinal();
}

Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

/**
* @extends RuleTestCase<ReturnTypeRule>
Expand Down Expand Up @@ -735,4 +736,14 @@ public function testTaggedUnions(): void
]);
}

public function testBug7904(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-7904.php'], []);
}

}
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-7904.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php // lint >= 8.0

namespace Bug7904;

interface Test {
public static function create(): static;
}

$impl = new class implements Test {
public static function create(): static {
return new self();
}
};

0 comments on commit a418c46

Please sign in to comment.