propertyFetchAnalyzer = $propertyFetchAnalyzer; $this->methodCallNodeFactory = $methodCallNodeFactory; $this->types = $types; $this->oldPropertyName = $oldPropertyName; $this->newMethodName = $newMethodName; } public function getDefinition(): RectorDefinition { return new RectorDefinition('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 , [ '$types' => ['SomeClass'], '$oldPropertyName' => 'oldProperty', '$newMethodName' => 'newMethodCall', ] ), ]); } /** * @return string[] */ public function getNodeTypes(): array { return [Assign::class]; } /** * @param Assign $assignNode */ public function refactor(Node $assignNode): ?Node { if ($this->propertyFetchAnalyzer->isTypesAndProperty( $assignNode->var, $this->types, $this->oldPropertyName ) === false) { return null; } /** @var PropertyFetch $propertyFetchNode */ $propertyFetchNode = $assignNode->var; /** @var Variable $propertyNode */ $propertyNode = $propertyFetchNode->var; return $this->methodCallNodeFactory->createWithVariableMethodNameAndArguments( $propertyNode, $this->newMethodName, [$assignNode->expr] ); } }