Skip to content

Commit

Permalink
ExistingClassInClassExtendsRule - do not complain about @final
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 10, 2020
1 parent 03a630e commit 3b2c806
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ public function isFinal(): bool
return $this->isFinal;
}

public function isFinalByKeyword(): bool
{
return $this->reflection->isFinal();
}

public function getTemplateTypeMap(): TemplateTypeMap
{
if ($this->templateTypeMap !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Classes/ExistingClassInClassExtendsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function processNode(Node $node, Scope $scope): array
$currentClassName !== null ? sprintf('Class %s', $currentClassName) : 'Anonymous class',
$extendedClassName
))->nonIgnorable()->build();
} elseif ($reflection->isFinal()) {
} elseif ($reflection->isFinalByKeyword()) {
$messages[] = RuleErrorBuilder::message(sprintf(
'%s extends final class %s.',
$currentClassName !== null ? sprintf('Class %s', $currentClassName) : 'Anonymous class',
Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Classes/data/extends-implements.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@ interface BazInterface extends FOOInterface
{

}

/**
* @final
*/
class FinalWithAnnotation
{

}

class ExtendsFinalWithAnnotation extends FinalWithAnnotation
{

}
23 changes: 23 additions & 0 deletions tests/PHPStan/Rules/Methods/data/overriding-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,26 @@ public function __construct()
}

}

class FinalWithAnnotation
{

/**
* @final
*/
public function doFoo()
{

}

}

class ExtendsFinalWithAnnotation extends FinalWithAnnotation
{

public function doFoo()
{

}

}

0 comments on commit 3b2c806

Please sign in to comment.