opt
/
cpanel
/
ea-wappspector
/
vendor
/
rector
/
rector
/
rules
/
Transform
/
Rector
/
Assign
➕ New
📤 Upload
✎ Editing:
PropertyAssignToMethodCallRector.php
← Back
<?php declare (strict_types=1); namespace Rector\Transform\Rector\Assign; use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Rector\AbstractRector; use Rector\Transform\ValueObject\PropertyAssignToMethodCall; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use RectorPrefix202411\Webmozart\Assert\Assert; /** * @see \Rector\Tests\Transform\Rector\Assign\PropertyAssignToMethodCallRector\PropertyAssignToMethodCallRectorTest */ final class PropertyAssignToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface { /** * @var PropertyAssignToMethodCall[] */ private $propertyAssignsToMethodCalls = []; public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Turns property assign of specific type and property name to method call', [new ConfiguredCodeSample(<<<'CODE_SAMPLE' $someObject = new SomeClass; $someObject->oldProperty = false; CODE_SAMPLE , <<<'CODE_SAMPLE' $someObject = new SomeClass; $someObject->newMethodCall(false); CODE_SAMPLE , [new PropertyAssignToMethodCall('SomeClass', 'oldProperty', 'newMethodCall')])]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Assign::class]; } /** * @param Assign $node */ public function refactor(Node $node) : ?Node { if (!$node->var instanceof PropertyFetch) { return null; } $propertyFetchNode = $node->var; /** @var Variable $propertyNode */ $propertyNode = $propertyFetchNode->var; foreach ($this->propertyAssignsToMethodCalls as $propertyAssignToMethodCall) { if (!$this->isName($propertyFetchNode, $propertyAssignToMethodCall->getOldPropertyName())) { continue; } if (!$this->isObjectType($propertyFetchNode->var, $propertyAssignToMethodCall->getObjectType())) { continue; } return $this->nodeFactory->createMethodCall($propertyNode, $propertyAssignToMethodCall->getNewMethodName(), [$node->expr]); } return null; } /** * @param mixed[] $configuration */ public function configure(array $configuration) : void { Assert::allIsAOf($configuration, PropertyAssignToMethodCall::class); $this->propertyAssignsToMethodCalls = $configuration; } }
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel