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

namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Fixture;

use Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Source\SortableBuilder;

final class RenameUsageWithSameNamedArrowParam
{
public function index(): array
{
$query = SortableBuilder::for(self::class)
->allowedSorts(fn (SortableBuilder $query): SortableBuilder => $query->defaultSort('x'))
->defaultSort('part_type');

return $query->jsonPaginate();
}
}

?>
-----
<?php

namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Fixture;

use Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Source\SortableBuilder;

final class RenameUsageWithSameNamedArrowParam
{
public function index(): array
{
$sortableBuilder = SortableBuilder::for(self::class)
->allowedSorts(fn (SortableBuilder $query): SortableBuilder => $query->defaultSort('x'))
->defaultSort('part_type');

return $sortableBuilder->jsonPaginate();
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector\Source;

final class SortableBuilder
{
public static function for(string $class): self
{
return new self();
}

public function allowedSorts(callable $callback): self
{
return $this;
}

public function defaultSort(string $sort): self
{
return $this;
}

public function jsonPaginate(): array
{
return [];
}
}
6 changes: 6 additions & 0 deletions rules/Naming/VariableRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ private function isParamInParentFunction(Variable $variable, ?FunctionLike $func
return false;
}

// the tracked function-like is only reset on enter, so it can linger past its own body;
// a variable located after it is no longer inside it and its params must be ignored
if ($variable->getStartTokenPos() > $functionLike->getEndTokenPos()) {
return false;
}

$scope = $variable->getAttribute(AttributeKey::SCOPE);
$functionLikeScope = $functionLike->getAttribute(AttributeKey::SCOPE);

Expand Down
Loading