Skip to content

Commit

Permalink
[CodingStyle] Make MakeInheritedMethodVisibilitySameAsParentRector sk…
Browse files Browse the repository at this point in the history
…ip magic methods and annotation methods (#137)
  • Loading branch information
TomasVotruba authored Jun 1, 2021
1 parent ea1e88f commit 743738b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Fixture;

use Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Source\NoMethodAnnotationHere;

/**
* @method some()
*/
final class SkipMethodAnnotation extends NoMethodAnnotationHere
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Source;

abstract class NoMethodAnnotationHere
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->isMagic()) {
return null;
}

$scope = $node->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
// possibly trait
Expand All @@ -93,12 +97,13 @@ public function refactor(Node $node): ?Node
$methodName = $this->getName($node->name);

foreach ($classReflection->getParents() as $parentClassReflection) {
if (! $parentClassReflection->hasMethod($methodName)) {
$nativeClassReflection = $parentClassReflection->getNativeReflection();

// the class reflection aboves takes also @method annotations into an account
if (! $nativeClassReflection->hasMethod($methodName)) {
continue;
}

$nativeClassReflection = $parentClassReflection->getNativeReflection();

$parentReflectionMethod = $nativeClassReflection->getMethod($methodName);
if ($this->isClassMethodCompatibleWithParentReflectionMethod($node, $parentReflectionMethod)) {
return null;
Expand Down

0 comments on commit 743738b

Please sign in to comment.