REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.57 KB
Close
/opt/cpanel/ea-wappspector/vendor/rector/rector/rules/Transform/Rector/Assign/PropertyAssignToMethodCallRector.php
Text
Base64
<?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
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 2
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
PropertyAssignToMethodCallRector.php
2.57 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
PropertyFetchToMethodCallRector.php
4.33 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).