Skip to content

Commit

Permalink
[ci-review] Rector Rectify
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 7, 2023
1 parent f93473e commit b8490f1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Rector/Closure/ServiceSettersToSettersAutodiscoveryRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Reflection\ReflectionProvider;
Expand All @@ -29,7 +31,7 @@
*/
final class ServiceSettersToSettersAutodiscoveryRector extends AbstractRector
{
private Solver $solver;
private readonly Solver $solver;

public function __construct(
private readonly SymfonyPhpClosureDetector $symfonyPhpClosureDetector,
Expand Down Expand Up @@ -98,9 +100,10 @@ public function refactor(Node $node): ?Node

$classNamesAndFilesPaths = $this->createClassNamesAndFilePaths($bareServicesSetMethodCalls);

$classNames = array_map(function (ClassNameAndFilePath $classNameAndFilePath) {
return $classNameAndFilePath->getClassName();
}, $classNamesAndFilesPaths);
$classNames = array_map(
fn (ClassNameAndFilePath $classNameAndFilePath) => $classNameAndFilePath->getClassName(),
$classNamesAndFilesPaths
);

$sharedNamespace = $this->solver->solve(...$classNames);
if (! is_string($sharedNamespace)) {
Expand All @@ -115,17 +118,17 @@ public function refactor(Node $node): ?Node
dirname($this->file->getFilePath())
);

$directoryConcat = new Node\Expr\BinaryOp\Concat(
new ConstFetch(new Node\Name('__DIR__')),
$directoryConcat = new Concat(
new ConstFetch(new Name('__DIR__')),
new String_('/' . $relativeDirectoryPath)
);
$args = [new Arg(new String_($sharedNamespace)), new Arg($directoryConcat)];
$loadMethodCall = new MethodCall(new Variable('services'), 'load', $args);
$node->stmts[] = new Expression($loadMethodCall);

// remove all method calls
foreach ($bareServicesSetMethodCalls as $bareServicesSetMethodCall) {
$this->removeNode($bareServicesSetMethodCall);
foreach ($bareServicesSetMethodCalls as $bareServiceSetMethodCall) {
$this->removeNode($bareServiceSetMethodCall);
}

return $node;
Expand Down Expand Up @@ -192,8 +195,8 @@ private function createClassNamesAndFilePaths(array $methodsCalls): array
{
$classNamesAndFilesPaths = [];

foreach ($methodsCalls as $methodsCall) {
$firstArg = $methodsCall->getArgs()[0];
foreach ($methodsCalls as $methodCall) {
$firstArg = $methodCall->getArgs()[0];
$serviceClassReference = $this->valueResolver->getValue($firstArg->value);

if (! is_string($serviceClassReference)) {
Expand Down

0 comments on commit b8490f1

Please sign in to comment.