Skip to content

Commit 27d45a8

Browse files
authored
[CodeQuality] Skip from route path /edit/{id} on ControllerMethodInjectionToConstructorRector (#877)
* [CodeQuality] Skip from route path /edit/{id} on ControllerMethodInjectionToConstructorRector * Fix * Fix
1 parent c476c9f commit 27d45a8

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector\Fixture;
6+
7+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8+
use Symfony\Component\HttpFoundation\Request;
9+
use Symfony\Component\Routing\Annotation\Route;
10+
11+
final class SkipFromRoutePath extends AbstractController
12+
{
13+
#[Route(path: '/edit/{id}', name: 'edit')]
14+
public function someAction(Request $request, ?string $id = null)
15+
{
16+
}
17+
}

rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PhpParser\Node\Expr\PropertyFetch;
1010
use PhpParser\Node\Expr\Variable;
1111
use PhpParser\Node\Identifier;
12-
use PhpParser\Node\Name;
12+
use PhpParser\Node\Name\FullyQualified;
1313
use PhpParser\Node\Stmt\Class_;
1414
use PhpParser\Node\Stmt\ClassMethod;
1515
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
@@ -117,19 +117,17 @@ public function refactor(Node $node): ?Node
117117

118118
foreach ($classMethod->getParams() as $key => $param) {
119119
// skip scalar and empty values, as not services
120-
if ($param->type === null || $param->type instanceof Identifier) {
120+
if ($param->type === null || ! $param->type instanceof FullyQualified) {
121121
continue;
122122
}
123123

124124
// request is allowed
125-
if ($param->type instanceof Name) {
126-
if ($this->isName($param->type, SymfonyClass::REQUEST)) {
127-
continue;
128-
}
125+
if ($this->isName($param->type, SymfonyClass::REQUEST)) {
126+
continue;
127+
}
129128

130-
if ($this->isNames($param->type, $entityClasses)) {
131-
continue;
132-
}
129+
if ($this->isNames($param->type, $entityClasses)) {
130+
continue;
133131
}
134132

135133
// @todo allow parameter converter

0 commit comments

Comments
 (0)