Skip to content

Conversation

@TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Oct 5, 2025

Reported by PHPStan, now fixed by Rector 👍

class Fixture
{
    public function run($value)
    {
-        return function () use ($value) {
+        return function () {
            return 'value';
        };
    }
}

@TomasVotruba TomasVotruba changed the title [dead-code] Add RemoveUnusedVariableUseRector [dead-code] Add RemoveUnusedClosureVariableUseRector Oct 5, 2025
@TomasVotruba TomasVotruba merged commit 8d22ced into main Oct 5, 2025
50 checks passed
@TomasVotruba TomasVotruba deleted the tv-dead-non-existing-use branch October 5, 2025 13:49
continue;
}

$isUseUsed = (bool) $this->betterNodeFinder->findVariableOfName($node->stmts, $useVariableName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should verify compact use as well, better use ExprUsedInNodeAnalyzer for it, I will create new PR for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


declare(strict_types=1);

namespace Rector\DeadCode\Rector\Concat;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should under Closure namespace:

-namespace Rector\DeadCode\Rector\Concat;
+namespace Rector\DeadCode\Rector\Closure;

I will create new PR for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +86 to +87
// reset keys, to keep as expected
$node->uses = array_values($node->uses);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed, already covered at NodeAttributeReIndexer, see

if ($node instanceof Closure) {
$node->uses = array_values($node->uses);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants