File manager - Edit - /var/www/payraty/helpdesk/vendor/rector/rector/vendor/rector/rector-nette/src/Rector/MethodCall/MergeDefaultsInGetConfigCompilerExtensionRector.php
Back
<?php declare (strict_types=1); namespace Rector\Nette\Rector\MethodCall; use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; use PHPStan\Type\ObjectType; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Nette\Tests\Rector\MethodCall\MergeDefaultsInGetConfigCompilerExtensionRector\MergeDefaultsInGetConfigCompilerExtensionRectorTest */ final class MergeDefaultsInGetConfigCompilerExtensionRector extends AbstractRector { public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Change $this->getConfig($defaults) to array_merge', [new CodeSample(<<<'CODE_SAMPLE' use Nette\DI\CompilerExtension; final class SomeExtension extends CompilerExtension { private $defaults = [ 'key' => 'value' ]; public function loadConfiguration() { $config = $this->getConfig($this->defaults); } } CODE_SAMPLE , <<<'CODE_SAMPLE' use Nette\DI\CompilerExtension; final class SomeExtension extends CompilerExtension { private $defaults = [ 'key' => 'value' ]; public function loadConfiguration() { $config = array_merge($this->defaults, $this->getConfig()); } } 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->isObjectType($node->var, new ObjectType('Nette\\DI\\CompilerExtension'))) { return null; } if (!$this->isName($node->name, 'getConfig')) { return null; } if (\count($node->args) !== 1) { return null; } $getConfigMethodCall = new MethodCall(new Variable('this'), 'getConfig'); $firstArgValue = $node->args[0]->value; return $this->nodeFactory->createFuncCall('array_merge', [$firstArgValue, $getConfigMethodCall]); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings