File manager - Edit - /var/www/payraty/helpdesk/vendor/rector/rector/vendor/rector/rector-symfony/src/Rector/MethodCall/GetToConstructorInjectionRector.php
Back
<?php declare (strict_types=1); namespace Rector\Symfony\Rector\MethodCall; use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use Rector\Core\Rector\AbstractRector; use Rector\Symfony\NodeAnalyzer\DependencyInjectionMethodCallAnalyzer; use Rector\Symfony\TypeAnalyzer\ContainerAwareAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Symfony\Tests\Rector\MethodCall\GetToConstructorInjectionRector\GetToConstructorInjectionRectorTest */ final class GetToConstructorInjectionRector extends AbstractRector { /** * @readonly * @var \Rector\Symfony\NodeAnalyzer\DependencyInjectionMethodCallAnalyzer */ private $dependencyInjectionMethodCallAnalyzer; /** * @readonly * @var \Rector\Symfony\TypeAnalyzer\ContainerAwareAnalyzer */ private $containerAwareAnalyzer; public function __construct(DependencyInjectionMethodCallAnalyzer $dependencyInjectionMethodCallAnalyzer, ContainerAwareAnalyzer $containerAwareAnalyzer) { $this->dependencyInjectionMethodCallAnalyzer = $dependencyInjectionMethodCallAnalyzer; $this->containerAwareAnalyzer = $containerAwareAnalyzer; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Turns fetching of dependencies via `$this->get()` to constructor injection in Command and Controller', [new CodeSample(<<<'CODE_SAMPLE' use Symfony\Bundle\FrameworkBundle\Controller\Controller; final class SomeController extend Controller { public function someMethod() { // ... $this->get('some_service'); } } CODE_SAMPLE , <<<'CODE_SAMPLE' use Symfony\Bundle\FrameworkBundle\Controller\Controller; final class SomeController extend Controller { public function __construct(SomeService $someService) { $this->someService = $someService; } public function someMethod() { $this->someService; } } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [MethodCall::class]; } /** * @param MethodCall $node */ public function refactor(Node $node) : ?Node { if (!$this->containerAwareAnalyzer->isGetMethodAwareType($node->var)) { return null; } if (!$this->isName($node->name, 'get')) { return null; } return $this->dependencyInjectionMethodCallAnalyzer->replaceMethodCallWithPropertyFetchAndDependency($node); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings