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,20 @@
<?php

declare(strict_types=1);

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

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class SkipConflictParamNameDifferentObject extends AbstractController
{
public function foo(Foo $service): void
{
dump($service);
}

public function bar(Bar $service): void
{
dump($service);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ public function refactor(Node $node): ?Node
continue;
}

if ($this->hasConflictedParamName(
$node,
$classMethod->name->toString(),
$this->getName($param->var),
$this->getName($param->type)
)) {
continue;
}

unset($classMethod->params[$key]);
$propertyMetadatas[] = new PropertyMetadata($this->getName($param->var), $paramType);
}
Expand Down Expand Up @@ -243,6 +252,33 @@ private function shouldSkipClassMethod(ClassMethod $classMethod): bool
return $this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod);
}

private function hasConflictedParamName(
Class_ $class,
string $currentClassMethodName,
string $paramName,
string $paramType
): bool {
foreach ($class->getMethods() as $classMethod) {
if ($this->isName($classMethod, $currentClassMethodName)) {
continue;
}

foreach ($classMethod->getParams() as $param) {
if (! $param->var instanceof Variable) {
continue;
}

if (! $this->isName($param->var, $paramName)) {
continue;
}

return $param->type instanceof FullyQualified && ! $this->isName($param->type, $paramType);
}
}

return false;
}

/**
* @param string[] $paramNamesToReplace
*/
Expand Down
Loading