Skip to content

Commit c301b38

Browse files
authored
[CodeQuality] Skip FOS\RestBundle ParamFetcher on ControllerMethodInjectionToConstructorRector (#881)
* [CodeQuality] Skip FOS\RestBundle ParamFetcher on ControllerMethodInjectionToConstructorRector * fix
1 parent edcfaa5 commit c301b38

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
9+
final class SkipParamFetcher extends AbstractController
10+
{
11+
public function someAction(\FOS\RestBundle\Request\ParamFetcher $paramFetcher)
12+
{
13+
}
14+
}

rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Rector\Rector\AbstractRector;
2020
use Rector\StaticTypeMapper\StaticTypeMapper;
2121
use Rector\Symfony\Bridge\NodeAnalyzer\ControllerMethodAnalyzer;
22+
use Rector\Symfony\Enum\FosClass;
2223
use Rector\Symfony\Enum\SensioAttribute;
2324
use Rector\Symfony\Enum\SymfonyClass;
2425
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
@@ -127,7 +128,7 @@ public function refactor(Node $node): ?Node
127128
}
128129

129130
// request is allowed
130-
if ($this->isName($param->type, SymfonyClass::REQUEST)) {
131+
if ($this->isNames($param->type, [SymfonyClass::REQUEST, FosClass::PARAM_FETCHER])) {
131132
continue;
132133
}
133134

src/Enum/FosClass.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Symfony\Enum;
6+
7+
final class FosClass
8+
{
9+
/**
10+
* @var string
11+
*/
12+
public const PARAM_FETCHER = 'FOS\RestBundle\Request\ParamFetcher';
13+
}

0 commit comments

Comments
 (0)