Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeQuality] FuncLikeToFirstClassCallableRector #6667

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

peterfox
Copy link
Contributor

Changes

  • Adds the FuncLikeToFirstClassCallableRector rule
  • Adds tests for the new rule
  • Added to the code quality set
  • Changes applied by the rule itself to Rector's own code through being added to the set
    • src/Configuration/RectorConfigBuilder.php
    • src/Util/ArrayParametersMerger.php

Why

This reduces the user of Closures and Arrow functions where they are basically redundant and code be replaced by a First-Class Callable instead of being wrapped in a closure.

-function ($parameter) { return Call::to($parameter); }
+Call::to(...);

Notes

I debated what group this should be in. It could be considered Code Quality but equally it could be Deadcode or even Code Style. I'm happy to change it based on feedback.

Risk

There might be some risk for this if used with closure binding e.g.

$function = function ($foo) { return $this->foo($foo); };
$function->bindTo($obj);

Might end up as

$function = $this->foo(...);
$function->bindTo($obj);

If that's a problem then I can make the rule avoid method calls of $this.

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.

1 participant