Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/NodeAnalyzer/FormAddMethodCallAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Symfony\NodeAnalyzer;

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Type\ObjectType;
use Rector\NodeNameResolver\NodeNameResolver;
Expand Down Expand Up @@ -43,6 +44,6 @@ public function isMatching(MethodCall $methodCall): bool
}

$firstArg = $args[1];
return $firstArg->value !== null;
return $firstArg->value instanceof Expr;
}
}
4 changes: 1 addition & 3 deletions src/NodeAnalyzer/LiteralCallLikeConstFetchReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function replaceArgOnPosition(
return null;
}

$classConstFetch = $this->nodeFactory->createClassConstFetch($className, $constantName);

$arg->value = $classConstFetch;
$arg->value = $this->nodeFactory->createClassConstFetch($className, $constantName);

return $callLike;
}
Expand Down
3 changes: 1 addition & 2 deletions src/NodeFactory/OnSuccessLogoutClassMethodFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public function createFromOnLogoutSuccessClassMethod(ClassMethod $onLogoutSucces
$this->replaceRequestWithGetRequest($onLogoutSuccessClassMethod);

$oldClassStmts = (array) $onLogoutSuccessClassMethod->stmts;
$classStmts = array_merge([$if], $oldClassStmts);
$classMethod->stmts = $classStmts;
$classMethod->stmts = array_merge([$if], $oldClassStmts);

return $classMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public function refactor(Node $node): ?Node
continue;
}

$paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($paramType, TypeKind::PARAM);
$param->type = $paramTypeNode;
$param->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($paramType, TypeKind::PARAM);

$hasChanged = true;
}
Expand Down
21 changes: 20 additions & 1 deletion src/Rector/ClassMethod/RemoveUnusedRequestParamRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer;
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -19,7 +22,9 @@
final class RemoveUnusedRequestParamRector extends AbstractRector
{
public function __construct(
private readonly ControllerAnalyzer $controllerAnalyzer
private readonly ControllerAnalyzer $controllerAnalyzer,
private readonly ReflectionResolver $reflectionResolver,
private readonly ClassChildAnalyzer $classChildAnalyzer,
) {
}

Expand Down Expand Up @@ -74,6 +79,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isAbstract() || $this->hasAbstractParentClassMethod($node)) {
return null;
}

if (! $this->controllerAnalyzer->isInsideController($node)) {
return null;
}
Expand Down Expand Up @@ -113,4 +122,14 @@ public function refactor(Node $node): ?Node

return null;
}

private function hasAbstractParentClassMethod(ClassMethod $classMethod): bool
{
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
if (! $classReflection instanceof ClassReflection) {
return false;
}

return $this->classChildAnalyzer->hasAbstractParentClassMethod($classReflection, $this->getName($classMethod));
}
}
8 changes: 2 additions & 6 deletions src/Rector/MethodCall/FormBuilderSetDataMapperRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,11 @@ public function refactor(Node $node): ?Node
return null;
}

$propertyPathAccessor = new New_(new FullyQualified(
$new = new New_(new FullyQualified(
'Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor'
));

$newArgumentValue = new New_(new FullyQualified(self::DATAMAPPER_CLASS), [
new Arg($propertyPathAccessor),
]);

$firstArg->value = $newArgumentValue;
$firstArg->value = new New_(new FullyQualified(self::DATAMAPPER_CLASS), [new Arg($new)]);

return $node;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Rector\Symfony\Tests\Rector\ClassMethod\RemoveUnusedRequestParamRector\Fixture;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

abstract class AbstractController extends Controller
{
abstract public function fooAction(Request $request): Response;
}

class DontOverrideParentAbstractClassMethodController extends AbstractController
{
public function fooAction(Request $request): Response
{
return new Response();
}

public function barAction(Request $request): Response
{
return new Response();
}
}

?>
-----
<?php

namespace Rector\Symfony\Tests\Rector\ClassMethod\RemoveUnusedRequestParamRector\Fixture;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

abstract class AbstractController extends Controller
{
abstract public function fooAction(Request $request): Response;
}

class DontOverrideParentAbstractClassMethodController extends AbstractController
{
public function fooAction(Request $request): Response
{
return new Response();
}

public function barAction(): Response
{
return new Response();
}
}

?>