Skip to content

Commit

Permalink
Closes #5725 Fixes #5724
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Mar 3, 2021
1 parent 2e31059 commit 6ef2e08
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\ObjectType;
Expand All @@ -20,6 +21,7 @@
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\NodeAnalyzer\ClassMethodExternalCallNodeAnalyzer;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodVisibilityVendorLockResolver;
use Symfony\Component\Routing\Annotation\Route;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -236,6 +238,28 @@ private function shouldSkipClassMethod(ClassMethod $classMethod, PhpDocInfo $php
return true;
}

return $phpDocInfo->hasByType(SymfonyRouteTagValueNode::class);
$hasSymfonyRoutePhpDoc = $phpDocInfo->hasByType(SymfonyRouteTagValueNode::class);
if ($hasSymfonyRoutePhpDoc) {
return true;
}

return $this->hasSymfonyRouteAttrGroup($classMethod);
}

private function hasSymfonyRouteAttrGroup(ClassMethod $classMethod): bool
{
foreach ($classMethod->attrGroups as $attrGroup) {
if ($attrGroup->attrs === []) {
continue;
}

foreach ($attrGroup->attrs as $attr) {
if ($attr->name instanceof Name && $attr->name->toString() === Route::class) {
return true;
}
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Rector\Privatization\Tests\Rector\ClassMethod\PrivatizeLocalOnlyMethod

use Symfony\Component\Routing\Annotation\Route;

final class FrontController
final class SkipSymfonyRouteAttribute
{
#[Route(path: '', name: 'homepage')]
public function homeAction() : Response
Expand Down

0 comments on commit 6ef2e08

Please sign in to comment.