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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector\Fixture;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class DoNotReplaceVariableAssign extends AbstractController
{
public function someAction(\Psr\Log\LoggerInterface $logger)
{
$logger = $this->modify($logger);
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector\Fixture;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class DoNotReplaceVariableAssign extends AbstractController
{
public function __construct(private readonly \Psr\Log\LoggerInterface $logger)
{
}
public function someAction()
{
$logger = $this->modify($this->logger);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
use Rector\NodeManipulator\ClassDependencyManipulator;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\PostRector\ValueObject\PropertyMetadata;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -190,7 +191,10 @@ public function refactor(Node $node): ?Node

if (! $this->isNames($node, $paramNamesToReplace)) {
return null;
}

if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === true) {
return null;
}

$propertyName = $this->getName($node);
Expand Down