mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-10 13:12:23 +00:00
manual update
This commit is contained in:
parent
ff4315b0d3
commit
b9c9005d78
|
@ -82,9 +82,12 @@ final class MergeIsCandidateRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Class_::class;
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,22 +187,23 @@ final class MergeIsCandidateRector extends AbstractRector
|
|||
{
|
||||
$paramTypes = $this->resolveSingleParamTypesFromClassMethod($refactorClassMethod);
|
||||
|
||||
$nodeToBeReturned = new Array_();
|
||||
|
||||
if (count($paramTypes) > 1) {
|
||||
$nodeToBeReturned = new Array_();
|
||||
foreach ($paramTypes as $paramType) {
|
||||
$classConstFetchNode = $this->createClassConstFetchFromClassName($paramType);
|
||||
$nodeToBeReturned->items[] = new ArrayItem($classConstFetchNode);
|
||||
}
|
||||
|
||||
} elseif (count($paramTypes) === 1) {
|
||||
$nodeToBeReturned = $this->createClassConstFetchFromClassName($paramTypes[0]);
|
||||
$nodeToBeReturned->items[] = $this->createClassConstFetchFromClassName($paramTypes[0]);
|
||||
} else { // fallback to basic node
|
||||
$nodeToBeReturned = $this->createClassConstFetchFromClassName('PhpParser\\Node');
|
||||
$nodeToBeReturned->items[] = $this->createClassConstFetchFromClassName('PhpParser\\Node');
|
||||
}
|
||||
|
||||
return $this->builderFactory->method('getNodeType')
|
||||
return $this->builderFactory->method('getNodeTypes')
|
||||
->makePublic()
|
||||
->setReturnType('string')
|
||||
->setReturnType('array')
|
||||
->addStmt(new Return_($nodeToBeReturned))
|
||||
->getNode();
|
||||
}
|
||||
|
|
|
@ -65,9 +65,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,9 +56,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassMethod::class;
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,9 +69,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classMethodNode): ?Node
|
||||
{
|
||||
if (! $classMethodNode instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($classMethodNode)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -55,9 +55,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,20 +68,17 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->methodCallAnalyzer->isMethods($methodCallNode, array_keys($this->oldToNewMethod))) {
|
||||
return null;
|
||||
}
|
||||
/** @var MethodCall $methodCallNode */
|
||||
$methodCallNode = $methodCallNode;
|
||||
|
||||
if (isset($methodCallNode->args[1]) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $methodCallNode->name;
|
||||
$oldMethodName = $identifierNode->name;
|
||||
|
|
|
@ -73,9 +73,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassMethod::class;
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,17 +86,10 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classMethodNode): ?Node
|
||||
{
|
||||
if (! $classMethodNode instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($classMethodNode)) {
|
||||
return null;
|
||||
}
|
||||
foreach ($this->annotationToMethod as $annotation => $method) {
|
||||
if ($this->docBlockAnalyzer->hasTag($classMethodNode, $annotation)) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
foreach ($this->annotationToMethod as $annotation => $method) {
|
||||
if (! $this->docBlockAnalyzer->hasTag($classMethodNode, $annotation)) {
|
||||
continue;
|
||||
|
|
|
@ -39,9 +39,12 @@ final class GetMockRector extends AbstractPHPUnitRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,9 +52,6 @@ final class GetMockRector extends AbstractPHPUnitRector
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -73,9 +73,12 @@ final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,9 +86,6 @@ final class AssertCompareToSpecificMethodRector extends AbstractPHPUnitRector
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -71,9 +71,12 @@ final class AssertComparisonToSpecificMethodRector extends AbstractPHPUnitRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,17 +84,12 @@ final class AssertComparisonToSpecificMethodRector extends AbstractPHPUnitRector
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->methodCallAnalyzer->isMethods($methodCallNode, ['assertTrue', 'assertFalse'])) {
|
||||
return null;
|
||||
}
|
||||
/** @var MethodCall $methodCallNode */
|
||||
$methodCallNode = $methodCallNode;
|
||||
$firstArgumentValue = $methodCallNode->args[0]->value;
|
||||
if (! $firstArgumentValue instanceof BinaryOp) {
|
||||
return null;
|
||||
|
|
|
@ -57,9 +57,12 @@ final class AssertFalseStrposToContainsRector extends AbstractPHPUnitRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,9 +70,6 @@ final class AssertFalseStrposToContainsRector extends AbstractPHPUnitRector
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -65,9 +65,12 @@ final class AssertInstanceOfComparisonRector extends AbstractPHPUnitRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,17 +78,12 @@ final class AssertInstanceOfComparisonRector extends AbstractPHPUnitRector
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->methodCallAnalyzer->isMethods($methodCallNode, array_keys($this->renameMethodsMap))) {
|
||||
return null;
|
||||
}
|
||||
/** @var MethodCall $methodCallNode */
|
||||
$methodCallNode = $methodCallNode;
|
||||
$firstArgumentValue = $methodCallNode->args[0]->value;
|
||||
if ($firstArgumentValue instanceof Instanceof_ === false) {
|
||||
return null;
|
||||
|
|
|
@ -55,9 +55,12 @@ final class AssertIssetToSpecificMethodRector extends AbstractPHPUnitRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,17 +68,12 @@ final class AssertIssetToSpecificMethodRector extends AbstractPHPUnitRector
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->methodCallAnalyzer->isMethods($methodCallNode, ['assertTrue', 'assertFalse'])) {
|
||||
return null;
|
||||
}
|
||||
/** @var MethodCall $methodCallNode */
|
||||
$methodCallNode = $methodCallNode;
|
||||
$firstArgumentValue = $methodCallNode->args[0]->value;
|
||||
// is property access
|
||||
if (! $firstArgumentValue instanceof Isset_) {
|
||||
|
|
|
@ -60,34 +60,35 @@ final class AssertNotOperatorRector extends AbstractPHPUnitRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class, StaticCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall $methodCallNode
|
||||
* @param MethodCall|StaticCall $node
|
||||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall && ! $methodCallNode instanceof StaticCall) {
|
||||
if (! $this->isInTestClass($node)) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isNormalOrStaticMethods($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
/** @var MethodCall $methodCallNode */
|
||||
$methodCallNode = $methodCallNode;
|
||||
$firstArgumentValue = $methodCallNode->args[0]->value;
|
||||
if ($firstArgumentValue instanceof BooleanNot === false) {
|
||||
return null;
|
||||
}
|
||||
$this->identifierRenamer->renameNodeWithMap($methodCallNode, $this->renameMethodsMap);
|
||||
|
||||
$oldArguments = $methodCallNode->args;
|
||||
if (! $this->isNormalOrStaticMethods($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$firstArgumentValue = $node->args[0]->value;
|
||||
if (! $firstArgumentValue instanceof BooleanNot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->identifierRenamer->renameNodeWithMap($node, $this->renameMethodsMap);
|
||||
|
||||
$oldArguments = $node->args;
|
||||
/** @var BooleanNot $negation */
|
||||
$negation = $oldArguments[0]->value;
|
||||
|
||||
|
@ -95,9 +96,9 @@ final class AssertNotOperatorRector extends AbstractPHPUnitRector
|
|||
|
||||
unset($oldArguments[0]);
|
||||
|
||||
$methodCallNode->args = array_merge([new Arg($expression)], $oldArguments);
|
||||
$node->args = array_merge([new Arg($expression)], $oldArguments);
|
||||
|
||||
return $methodCallNode;
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function isNormalOrStaticMethods(Node $node): bool
|
||||
|
|
|
@ -76,9 +76,12 @@ final class AssertPropertyExistsRector extends AbstractPHPUnitRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,9 +51,12 @@ final class AssertRegExpRector extends AbstractPHPUnitRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,9 +55,12 @@ final class AssertSameBoolNullToSpecificMethodRector extends AbstractPHPUnitRect
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -87,9 +87,12 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,17 +100,12 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractPH
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->isInTestClass($methodCallNode)) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->methodCallAnalyzer->isMethods($methodCallNode, array_keys($this->renameMethodsMap))) {
|
||||
return null;
|
||||
}
|
||||
/** @var MethodCall $methodCallNode */
|
||||
$methodCallNode = $methodCallNode;
|
||||
/** @var FuncCall $firstArgumentValue */
|
||||
$firstArgumentValue = $methodCallNode->args[0]->value;
|
||||
if (! $this->isNamedFunction($firstArgumentValue)) {
|
||||
|
|
|
@ -88,9 +88,12 @@ final class AssertTrueFalseToSpecificMethodRector extends AbstractPHPUnitRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,9 +40,12 @@ final class CatchAndClosureUseNameRector extends AbstractRector
|
|||
$this->propertyFetchNodeFactory = $propertyFetchNodeFactory;
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return PropertyFetch::class;
|
||||
return [PropertyFetch::class];
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
|
@ -64,6 +67,7 @@ final class CatchAndClosureUseNameRector extends AbstractRector
|
|||
) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parentNode = $propertyFetchNode->getAttribute(Attribute::PARENT_NODE);
|
||||
if ($parentNode instanceof PropertyFetch) {
|
||||
return $propertyFetchNode;
|
||||
|
|
|
@ -86,9 +86,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return PropertyFetch::class;
|
||||
return [PropertyFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,8 +102,7 @@ CODE_SAMPLE
|
|||
if (! $this->propertyFetchAnalyzer->isTypes($propertyFetchNode, array_keys($this->typeToPropertiesMap))) {
|
||||
return null;
|
||||
}
|
||||
/** @var PropertyFetch $propertyFetchNode */
|
||||
$propertyFetchNode = $propertyFetchNode;
|
||||
|
||||
$variableNode = $propertyFetchNode->var;
|
||||
$nodeTypes = $this->nodeTypeResolver->resolve($variableNode);
|
||||
$properties = $this->matchTypeToProperties($nodeTypes);
|
||||
|
|
|
@ -36,9 +36,12 @@ final class ParamAndStaticVarNameRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return PropertyFetch::class;
|
||||
return [PropertyFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,6 +53,7 @@ final class ParamAndStaticVarNameRector extends AbstractRector
|
|||
if ($this->propertyFetchAnalyzer->isTypesAndProperty($propertyFetchNode, $types, 'name') === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->identifierRenamer->renameNode($propertyFetchNode, 'var');
|
||||
|
||||
return new PropertyFetch($propertyFetchNode, 'name');
|
||||
|
|
|
@ -47,9 +47,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Return_::class;
|
||||
return [Return_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,20 +60,20 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $returnNode): ?Node
|
||||
{
|
||||
if (! $returnNode instanceof Return_) {
|
||||
return null;
|
||||
}
|
||||
if (! $returnNode->expr instanceof ConstFetch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodName = $returnNode->getAttribute(Attribute::METHOD_NAME);
|
||||
if ($methodName !== 'leaveNode') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = $returnNode->expr->name->toString();
|
||||
if (($value === 'false') === false) {
|
||||
if ($value !== 'false') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$returnNode->expr = $this->nodeFactory->createClassConstant('PhpParser\NodeTraverser', 'REMOVE_NODE');
|
||||
|
||||
return $returnNode;
|
||||
|
|
|
@ -45,9 +45,12 @@ final class SetLineRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,9 +44,12 @@ final class UseWithAliasRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return PropertyFetch::class;
|
||||
return [PropertyFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,9 +92,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassMethod::class;
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,9 +105,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classMethodNode): ?Node
|
||||
{
|
||||
if (! $classMethodNode instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
if ($this->docBlockAnalyzer->hasTag($classMethodNode, 'Template') === false) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -22,9 +22,12 @@ final class ConstantToStaticCallRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ConstFetch::class;
|
||||
return [ConstFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,9 +21,12 @@ final class DefineConstantToStaticCallRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return FuncCall::class;
|
||||
return [FuncCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,17 +35,17 @@ final class DefineConstantToStaticCallRector extends AbstractRector
|
|||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (count($node->args) !== 1) {
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
|
||||
$argumentValue = $node->args[0]->value;
|
||||
if (! $argumentValue instanceof String_) {
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
|
||||
// @todo make configurable
|
||||
if (! Strings::startsWith($argumentValue->value, 'SS_')) {
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
|
||||
// @todo make configurable
|
||||
|
|
|
@ -51,9 +51,12 @@ final class ReplaceCreateMethodWithoutReviewerRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,7 +50,10 @@ final class ConsoleExceptionToErrorEventConstantRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassConstFetch::class, String_::class];
|
||||
}
|
||||
|
@ -61,13 +64,13 @@ final class ConsoleExceptionToErrorEventConstantRector extends AbstractRector
|
|||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($this->classConstAnalyzer->isTypeAndNames($node, self::CONSOLE_EVENTS_CLASS, ['EXCEPTION'])) {
|
||||
return $this->nodeFactory->createClassConstant(self::CONSOLE_EVENTS_CLASS, 'ERROR');
|
||||
}
|
||||
if (! $node instanceof String_) {
|
||||
return null;
|
||||
|
||||
if ($node instanceof String_ && $node->value === 'console.exception') {
|
||||
return $this->nodeFactory->createClassConstant(self::CONSOLE_EVENTS_CLASS, 'ERROR');
|
||||
}
|
||||
if (($node->value === 'console.exception') === false) {
|
||||
return null;
|
||||
}
|
||||
return $this->nodeFactory->createClassConstant(self::CONSOLE_EVENTS_CLASS, 'ERROR');
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Rector\Symfony\Rector\Controller;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Builder\IdentifierRenamer;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
|
@ -54,9 +55,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Node::class;
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
public function refactor(Node $node): ?Node
|
||||
|
|
|
@ -65,9 +65,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,9 +56,12 @@ final class RedirectToRouteRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,9 +41,12 @@ final class ContainerBuilderCompileEnvArgumentRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,9 +60,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,9 +62,12 @@ final class FormTypeGetParentRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return String_::class;
|
||||
return [String_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,17 +75,16 @@ final class FormTypeGetParentRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $stringNode): ?Node
|
||||
{
|
||||
if (! $stringNode instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->formTypeStringToTypeProvider->hasClassForName($stringNode->value)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->isParentTypeAndMethod($stringNode, $this->abstractTypeClass, 'getParent')) {
|
||||
}
|
||||
if ($this->isParentTypeAndMethod($stringNode, $this->abstractTypeExtensionClass, 'getExtendedType') === false) {
|
||||
|
||||
if (! $this->isParentTypeAndMethod($stringNode, $this->abstractTypeClass, 'getParent') &&
|
||||
! $this->isParentTypeAndMethod($stringNode, $this->abstractTypeExtensionClass, 'getExtendedType')
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$class = $this->formTypeStringToTypeProvider->getClassForName($stringNode->value);
|
||||
|
||||
return $this->nodeFactory->createClassConstantReference($class);
|
||||
|
@ -95,8 +97,6 @@ final class FormTypeGetParentRector extends AbstractRector
|
|||
return false;
|
||||
}
|
||||
|
||||
$methodName = $node->getAttribute(Attribute::METHOD_NAME);
|
||||
|
||||
return $methodName === $method;
|
||||
return $node->getAttribute(Attribute::METHOD_NAME) === $method;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,9 +49,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return String_::class;
|
||||
return [String_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,27 +62,30 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $stringNode): ?Node
|
||||
{
|
||||
if (! $stringNode instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
if (! isset($this->oldToNewOption[$stringNode->value])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$arrayItemParentNode = $stringNode->getAttribute(Attribute::PARENT_NODE);
|
||||
if (! $arrayItemParentNode instanceof ArrayItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$arrayParentNode = $arrayItemParentNode->getAttribute(Attribute::PARENT_NODE);
|
||||
|
||||
/** @var MethodCall $argParentNode */
|
||||
$argParentNode = $arrayParentNode->getAttribute(Attribute::PARENT_NODE);
|
||||
|
||||
/** @var MethodCall|Node $methodCallNode */
|
||||
$methodCallNode = $argParentNode->getAttribute(Attribute::PARENT_NODE);
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (((string) $methodCallNode->name === 'add') === false) {
|
||||
|
||||
if ((string) $methodCallNode->name !== 'add') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->nodeFactory->createString($this->oldToNewOption[$stringNode->value]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,9 +48,12 @@ final class StringFormTypeToClassRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return String_::class;
|
||||
return [String_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,9 +61,6 @@ final class StringFormTypeToClassRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $stringNode): ?Node
|
||||
{
|
||||
if (! $stringNode instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
if (! $this->formTypeStringToTypeProvider->hasClassForNameWithPrefix($stringNode->value)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -59,13 +59,9 @@ abstract class AbstractToConstructorInjectionRector extends AbstractRector
|
|||
$this->methodCallAnalyzer = $methodCallAnalyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall $methodCallNode
|
||||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
protected function processMethodCallNode(MethodCall $methodCallNode): ?Node
|
||||
{
|
||||
$serviceType = $this->getServiceTypeFromMethodCallArgument($methodCallNode);
|
||||
|
||||
if ($serviceType === null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Rector\Symfony\Rector\FrameworkBundle;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use Rector\NodeTypeResolver\Node\Attribute;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
@ -67,18 +68,32 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall $methodCallNode
|
||||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $this->methodCallAnalyzer->isTypeAndMethod(
|
||||
$node,
|
||||
$methodCallNode,
|
||||
'Symfony\Component\DependencyInjection\ContainerInterface',
|
||||
'get'
|
||||
)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
$parentClassName = $node->getAttribute(Attribute::PARENT_CLASS_NAME);
|
||||
$parentClassName = $methodCallNode->getAttribute(Attribute::PARENT_CLASS_NAME);
|
||||
if (! in_array($parentClassName, $this->containerAwareParentTypes, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return in_array($parentClassName, $this->containerAwareParentTypes, true);
|
||||
return $this->processMethodCallNode($methodCallNode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,9 +92,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,9 +105,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if ($this->methodCallAnalyzer->isTypeAndMethod(
|
||||
$methodCallNode,
|
||||
$this->controllerClass,
|
||||
|
|
|
@ -10,14 +10,9 @@ use Rector\RectorDefinition\RectorDefinition;
|
|||
final class GetToConstructorInjectionRector extends AbstractToConstructorInjectionRector
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @var string[]
|
||||
*/
|
||||
private $controllerClass;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $traitClass;
|
||||
private $getMethodAwareTypes = [];
|
||||
|
||||
/**
|
||||
* @todo merge to $getMethodAwareTypes
|
||||
|
@ -26,8 +21,8 @@ final class GetToConstructorInjectionRector extends AbstractToConstructorInjecti
|
|||
string $controllerClass = 'Symfony\Bundle\FrameworkBundle\Controller\Controller',
|
||||
string $traitClass = 'Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait'
|
||||
) {
|
||||
$this->controllerClass = $controllerClass;
|
||||
$this->traitClass = $traitClass;
|
||||
$this->getMethodAwareTypes[] = $controllerClass;
|
||||
$this->getMethodAwareTypes[] = $traitClass;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
|
@ -66,12 +61,23 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
return false;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall $methodCallNode
|
||||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $this->methodCallAnalyzer->isTypesAndMethod($methodCallNode, $this->getMethodAwareTypes, 'get')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->methodCallAnalyzer->isTypesAndMethod($node, [$this->controllerClass, $this->traitClass], 'get');
|
||||
return $this->processMethodCallNode($methodCallNode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,30 +80,32 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class, MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|MethodCall $classMethodOrMethodCallNode
|
||||
* @param ClassMethod|MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $classMethodOrMethodCallNode): ?Node
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($this->isActionWithGetRequestInBody($classMethodOrMethodCallNode)) {
|
||||
if ($this->isGetRequestInAction($node)) {
|
||||
return $this->nodeFactory->createVariable('request');
|
||||
}
|
||||
if ($this->isGetRequestInAction($classMethodOrMethodCallNode) === false) {
|
||||
return null;
|
||||
}
|
||||
if ($classMethodOrMethodCallNode instanceof ClassMethod) {
|
||||
|
||||
if ($this->isActionWithGetRequestInBody($node)) {
|
||||
$requestParam = $this->nodeFactory->createParam('request', 'Symfony\Component\HttpFoundation\Request');
|
||||
|
||||
$classMethodOrMethodCallNode->params[] = $requestParam;
|
||||
$node->params[] = $requestParam;
|
||||
|
||||
return $classMethodOrMethodCallNode;
|
||||
return $node;
|
||||
}
|
||||
|
||||
return $this->nodeFactory->createVariable('request');
|
||||
return null;
|
||||
}
|
||||
|
||||
private function isActionWithGetRequestInBody(Node $node): bool
|
||||
|
|
|
@ -51,9 +51,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,9 +43,12 @@ final class ProcessBuilderInstanceRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return StaticCall::class;
|
||||
return [StaticCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,6 +63,7 @@ final class ProcessBuilderInstanceRector extends AbstractRector
|
|||
) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new New_($staticCallNode->class, $staticCallNode->args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,29 +41,32 @@ final class ConstraintUrlOptionRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ConstFetch::class;
|
||||
return [ConstFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstFetch $node
|
||||
* @param ConstFetch $constFetchNode
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
public function refactor(Node $constFetchNode): ?Node
|
||||
{
|
||||
if (! $node instanceof ConstFetch) {
|
||||
if ($constFetchNode->name->toString() !== 'true') {
|
||||
return null;
|
||||
}
|
||||
if ($node->name->toString() !== 'true') {
|
||||
return null;
|
||||
}
|
||||
$prevNode = $node->getAttribute(Attribute::PREVIOUS_NODE);
|
||||
|
||||
$prevNode = $constFetchNode->getAttribute(Attribute::PREVIOUS_NODE);
|
||||
if (! $prevNode instanceof String_) {
|
||||
return null;
|
||||
}
|
||||
if (($prevNode->value === 'checkDNS') === false) {
|
||||
|
||||
if ($prevNode->value !== 'checkDNS') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->nodeFactory->createClassConstant(self::URL_CONSTRAINT_CLASS, 'CHECK_DNS_TYPE_ANY');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Rector\Symfony\Rector\VarDumper;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Node\NodeFactory;
|
||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||
|
@ -56,38 +56,36 @@ final class VarDumperTestTraitMethodArgsRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return StaticCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StaticCall $node
|
||||
* @param MethodCall $methodCallNode
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $this->methodCallAnalyzer->isTypeAndMethods(
|
||||
$node,
|
||||
$methodCallNode,
|
||||
$this->traitName,
|
||||
['assertDumpEquals', 'assertDumpMatchesFormat']
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
/** @var StaticCall $staticCallNode */
|
||||
$staticCallNode = $node;
|
||||
if (count($staticCallNode->args) <= 2 || $staticCallNode->args[2]->value instanceof ConstFetch) {
|
||||
|
||||
if (count($methodCallNode->args) <= 2 || $methodCallNode->args[2]->value instanceof ConstFetch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$methodArguments = $node->args;
|
||||
if ($methodCallNode->args[2]->value instanceof String_) {
|
||||
$methodCallNode->args[3] = $methodCallNode->args[2];
|
||||
$methodCallNode->args[2] = $this->nodeFactory->createArg($this->nodeFactory->createNullConstant());
|
||||
|
||||
if ($methodArguments[2]->value instanceof String_) {
|
||||
$methodArguments[3] = $methodArguments[2];
|
||||
$methodArguments[2] = $this->nodeFactory->createArg($this->nodeFactory->createNullConstant());
|
||||
|
||||
$node->args = $methodArguments;
|
||||
|
||||
return $node;
|
||||
return $methodCallNode;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -31,10 +31,10 @@ parameters:
|
|||
- '#Call to function in_array\(\) with arguments string, array<array<string\|false>> and true will always evaluate to false#'
|
||||
|
||||
# known values
|
||||
- '#Access to an undefined property PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Stmt\\ClassMethod::\$params#'
|
||||
- '#Cannot call method getName\(\) on PHPStan\\Reflection\\ClassReflection\|null#' # 1
|
||||
- '#Parameter \#1 \$classReflection of method Rector\\NodeTypeResolver\\Reflection\\ClassReflectionTypesResolver::resolve\(\) expects PHPStan\\Reflection\\ClassReflection, PHPStan\\Reflection\\ClassReflection|null given#'
|
||||
- '#Cannot call method getAttribute\(\) on PhpParser\\Node\\Name\|null#'
|
||||
- '#Cannot call method getName\(\) on Rector\\Builder\\Class_\\VariableInfo\|null#'
|
||||
- '#Cannot call method getBasename\(\) on Symfony\\Component\\Finder\\SplFileInfo\|null#'
|
||||
- '#Cannot call method getText\(\) on PhpParser\\Comment\\Doc\|null#'
|
||||
|
||||
|
|
|
@ -10,17 +10,12 @@ interface PhpRectorInterface extends NodeVisitor, RectorInterface
|
|||
/**
|
||||
* A node this Rector listens to
|
||||
*
|
||||
* @return string
|
||||
* @return string[]
|
||||
*/
|
||||
// public function getNodeType(): string
|
||||
|
||||
// @todo remove after swtich to getNodeType()
|
||||
// public function isCandidate(Node $node): bool;
|
||||
public function getNodeTypes(): array;
|
||||
|
||||
/**
|
||||
* Process Node of matched type
|
||||
*
|
||||
* @return null|Node|void
|
||||
*/
|
||||
public function refactor(Node $node);
|
||||
public function refactor(Node $node): ?Node;
|
||||
}
|
||||
|
|
|
@ -50,24 +50,21 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
|
|||
*/
|
||||
final public function enterNode(Node $node)
|
||||
{
|
||||
if (method_exists($this, 'getNodeType')) {
|
||||
if (! is_a($node, $this->getNodeType(), true)) { // == basically "isCandidate()" condition
|
||||
return null;
|
||||
}
|
||||
} elseif (method_exists($this, 'isCandidate')) {
|
||||
if (! $this->isCandidate($node)) {
|
||||
return null;
|
||||
}
|
||||
$nodeClass = get_class($node);
|
||||
if (! $this->isMatchingNodeType($nodeClass)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$newNode = $this->refactor($node);
|
||||
|
||||
// nothing has changed, return original node
|
||||
if ($newNode !== null) {
|
||||
return $newNode;
|
||||
}
|
||||
|
||||
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
||||
if ($this->removeNode) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,4 +94,15 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
|
|||
{
|
||||
$this->expressionAdder->addNodeAfterNode($newNode, $positionNode);
|
||||
}
|
||||
|
||||
private function isMatchingNodeType(string $nodeClass): bool
|
||||
{
|
||||
foreach ($this->getNodeTypes() as $nodeType) {
|
||||
if (is_a($nodeClass, $nodeType, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,10 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class, Property::class];
|
||||
}
|
||||
|
@ -102,6 +105,7 @@ CODE_SAMPLE
|
|||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Node $parentNode */
|
||||
$parentNode = $node->getAttribute(Attribute::PARENT_NODE);
|
||||
$parentNodeTypes = $this->nodeTypeResolver->resolve($parentNode);
|
||||
|
@ -112,10 +116,11 @@ CODE_SAMPLE
|
|||
|
||||
$this->activeAnnotationMap = $annotationMap;
|
||||
|
||||
if ($this->hasAnyAnnotation($node)) {
|
||||
if (! $this->hasAnyAnnotation($node)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
foreach ($this->activeAnnotationMap as $oldAnnotation => $newAnnotation) {
|
||||
$this->docBlockAnalyzer->replaceAnnotationInNode($node, $oldAnnotation, $newAnnotation);
|
||||
}
|
||||
|
|
|
@ -66,9 +66,12 @@ final class ActionInjectionToConstructorInjectionRector extends AbstractRector
|
|||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Class_::class;
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
|
@ -112,18 +115,14 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classNode): ?Node
|
||||
{
|
||||
if (! $classNode instanceof Class_) {
|
||||
return null;
|
||||
}
|
||||
if (Strings::endsWith((string) $classNode->name, 'Controller') === false) {
|
||||
return null;
|
||||
}
|
||||
foreach ($classNode->stmts as $stmt) {
|
||||
if (! $stmt instanceof ClassMethod) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->processClassMethod($classNode, $stmt);
|
||||
foreach ($classNode->stmts as $stmt) {
|
||||
if ($stmt instanceof ClassMethod) {
|
||||
$this->processClassMethod($classNode, $stmt);
|
||||
}
|
||||
}
|
||||
|
||||
return $classNode;
|
||||
|
|
|
@ -55,34 +55,6 @@ final class AnnotatedPropertyInjectToConstructorInjectionRector extends Abstract
|
|||
$this->annotation = $annotation;
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
{
|
||||
return Property::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Property $propertyNode
|
||||
*/
|
||||
public function refactor(Node $propertyNode): Node
|
||||
{
|
||||
if (! $propertyNode instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
if ($propertyNode->isPrivate()) {
|
||||
return null;
|
||||
}
|
||||
if ($this->docBlockAnalyzer->hasTag($propertyNode, $this->annotation) === false) {
|
||||
return null;
|
||||
}
|
||||
$this->docBlockAnalyzer->removeTagFromNode($propertyNode, $this->annotation);
|
||||
|
||||
$propertyNode->flags = Class_::MODIFIER_PRIVATE;
|
||||
|
||||
$this->addPropertyToCollector($propertyNode);
|
||||
|
||||
return $propertyNode;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
|
@ -117,6 +89,37 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Property::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Property $propertyNode
|
||||
*/
|
||||
public function refactor(Node $propertyNode): ?Node
|
||||
{
|
||||
if ($propertyNode->isPrivate()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->docBlockAnalyzer->hasTag($propertyNode, $this->annotation)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->docBlockAnalyzer->removeTagFromNode($propertyNode, $this->annotation);
|
||||
|
||||
// set to private
|
||||
$propertyNode->flags = Class_::MODIFIER_PRIVATE;
|
||||
|
||||
$this->addPropertyToCollector($propertyNode);
|
||||
|
||||
return $propertyNode;
|
||||
}
|
||||
|
||||
private function addPropertyToCollector(Property $propertyNode): void
|
||||
{
|
||||
$propertyTypes = $this->nodeTypeResolver->resolve($propertyNode);
|
||||
|
|
|
@ -6,7 +6,6 @@ use Nette\Utils\Strings;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Builder\Class_\VariableInfo;
|
||||
use Rector\Configuration\Rector\Architecture\DependencyInjection\VariablesToPropertyFetchCollection;
|
||||
use Rector\Node\PropertyFetchNodeFactory;
|
||||
use Rector\NodeTypeResolver\Node\Attribute;
|
||||
|
@ -22,11 +21,6 @@ final class ReplaceVariableByPropertyFetchRector extends AbstractRector
|
|||
*/
|
||||
private $variablesToPropertyFetchCollection;
|
||||
|
||||
/**
|
||||
* @var VariableInfo|null
|
||||
*/
|
||||
private $activeVariableInfo;
|
||||
|
||||
/**
|
||||
* @var PropertyFetchNodeFactory
|
||||
*/
|
||||
|
@ -97,9 +91,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Variable::class;
|
||||
return [Variable::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,13 +104,11 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $variableNode): ?Node
|
||||
{
|
||||
$this->activeVariableInfo = null;
|
||||
if (! $variableNode instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
$activeVariableInfo = null;
|
||||
if (! $this->isInControllerActionMethod($variableNode)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->variablesToPropertyFetchCollection->getVariableInfos() as $variableInfo) {
|
||||
if ($variableNode->name !== $variableInfo->getName()) {
|
||||
continue;
|
||||
|
@ -121,11 +116,16 @@ CODE_SAMPLE
|
|||
|
||||
$nodeTypes = $this->nodeTypeResolver->resolve($variableNode);
|
||||
if ($nodeTypes === $variableInfo->getTypes()) {
|
||||
$this->activeVariableInfo = $variableInfo;
|
||||
$activeVariableInfo = $variableInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return $this->propertyFetchNodeFactory->createLocalWithPropertyName($this->activeVariableInfo->getName());
|
||||
|
||||
if ($activeVariableInfo === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->propertyFetchNodeFactory->createLocalWithPropertyName($activeVariableInfo->getName());
|
||||
}
|
||||
|
||||
private function isInControllerActionMethod(Node $node): bool
|
||||
|
|
|
@ -122,9 +122,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Class_::class;
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,20 +135,20 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $node instanceof Class_) {
|
||||
return null;
|
||||
}
|
||||
if (! $node->extends) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parentClassName = $node->getAttribute(Attribute::PARENT_CLASS_NAME);
|
||||
if ($parentClassName !== $this->entityRepositoryClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$className = $node->getAttribute(Attribute::CLASS_NAME);
|
||||
if (Strings::endsWith($className, 'Repository') === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// remove parent class
|
||||
$node->extends = null;
|
||||
|
||||
|
|
|
@ -77,9 +77,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,9 +90,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $methodCallNode): ?Node
|
||||
{
|
||||
if (! $methodCallNode instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
// of type...
|
||||
if (! $methodCallNode->name instanceof Identifier) {
|
||||
return null;
|
||||
|
|
|
@ -103,9 +103,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,6 +72,8 @@ abstract class AbstractArgumentRector extends AbstractRector
|
|||
if ($node instanceof ClassMethod) {
|
||||
return $node->params;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,9 +90,4 @@ abstract class AbstractArgumentRector extends AbstractRector
|
|||
$node->params = $argumentsOrParameters;
|
||||
}
|
||||
}
|
||||
|
||||
protected function isValidInstance(Node $node): bool
|
||||
{
|
||||
return $node instanceof ClassMethod || $node instanceof MethodCall || $node instanceof StaticCall;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,6 @@ final class ArgumentAdderRector extends AbstractArgumentRector
|
|||
*/
|
||||
private $recipes = [];
|
||||
|
||||
/**
|
||||
* @var ArgumentAdderRecipe[]
|
||||
*/
|
||||
private $activeRecipes = [];
|
||||
|
||||
/**
|
||||
* @param mixed[] $argumentChangesByMethodAndType
|
||||
*/
|
||||
|
@ -90,7 +85,10 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [MethodCall::class, StaticCall::class, ClassMethod::class];
|
||||
}
|
||||
|
@ -98,17 +96,15 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param MethodCall|StaticCall|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): Node
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isValidInstance($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->activeRecipes = $this->matchArgumentChanges($node);
|
||||
if ((bool) $this->activeRecipes === false) {
|
||||
$matchedRecipes = $this->matchArgumentChanges($node);
|
||||
if ((bool) $matchedRecipes === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$argumentsOrParameters = $this->getNodeArgumentsOrParameters($node);
|
||||
$argumentsOrParameters = $this->processArgumentNodes($argumentsOrParameters);
|
||||
$argumentsOrParameters = $this->processArgumentNodes($argumentsOrParameters, $matchedRecipes);
|
||||
|
||||
$this->setNodeArgumentsOrParameters($node, $argumentsOrParameters);
|
||||
|
||||
|
@ -133,11 +129,12 @@ CODE_SAMPLE
|
|||
|
||||
/**
|
||||
* @param mixed[] $argumentNodes
|
||||
* @param ArgumentAdderRecipe[] $argumentAdderRecipes
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function processArgumentNodes(array $argumentNodes): array
|
||||
private function processArgumentNodes(array $argumentNodes, array $argumentAdderRecipes): array
|
||||
{
|
||||
foreach ($this->activeRecipes as $argumentReplacerRecipe) {
|
||||
foreach ($argumentAdderRecipes as $argumentReplacerRecipe) {
|
||||
$position = $argumentReplacerRecipe->getPosition();
|
||||
|
||||
$argumentNodes[$position] = BuilderHelpers::normalizeValue($argumentReplacerRecipe->getDefaultValue());
|
||||
|
|
|
@ -23,11 +23,6 @@ final class ArgumentDefaultValueReplacerRector extends AbstractArgumentRector
|
|||
*/
|
||||
private $recipes = [];
|
||||
|
||||
/**
|
||||
* @var ArgumentDefaultValueReplacerRecipe[]
|
||||
*/
|
||||
private $activeRecipe = [];
|
||||
|
||||
/**
|
||||
* @var ConstExprEvaluator
|
||||
*/
|
||||
|
@ -84,7 +79,10 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [MethodCall::class, StaticCall::class, ClassMethod::class];
|
||||
}
|
||||
|
@ -92,19 +90,17 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param MethodCall|StaticCall|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): Node
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isValidInstance($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->activeRecipe = $this->matchArgumentChanges($node);
|
||||
if ((bool) $this->activeRecipe === false) {
|
||||
$matchedRecipes = $this->matchArgumentChanges($node);
|
||||
if (! $matchedRecipes) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Arg[] $argumentsOrParameters */
|
||||
$argumentsOrParameters = $this->getNodeArgumentsOrParameters($node);
|
||||
|
||||
$argumentsOrParameters = $this->processArgumentNodes($argumentsOrParameters);
|
||||
$argumentsOrParameters = $this->processArgumentNodes($argumentsOrParameters, $matchedRecipes);
|
||||
|
||||
$this->setNodeArgumentsOrParameters($node, $argumentsOrParameters);
|
||||
|
||||
|
@ -129,11 +125,12 @@ CODE_SAMPLE
|
|||
|
||||
/**
|
||||
* @param Arg[] $argumentNodes
|
||||
* @param ArgumentDefaultValueReplacerRecipe[] $matchedRecipes
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function processArgumentNodes(array $argumentNodes): array
|
||||
private function processArgumentNodes(array $argumentNodes, array $matchedRecipes): array
|
||||
{
|
||||
foreach ($this->activeRecipe as $recipe) {
|
||||
foreach ($matchedRecipes as $recipe) {
|
||||
if (is_scalar($recipe->getBefore())) {
|
||||
// simple 1 argument match
|
||||
$argumentNodes = $this->processScalarReplacement($argumentNodes, $recipe);
|
||||
|
|
|
@ -66,7 +66,10 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [MethodCall::class, StaticCall::class, ClassMethod::class];
|
||||
}
|
||||
|
@ -74,11 +77,8 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param MethodCall|StaticCall|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): Node
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isValidInstance($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->activeRecipes = $this->matchArgumentChanges($node);
|
||||
if ((bool) $this->activeRecipes === false) {
|
||||
return null;
|
||||
|
|
|
@ -80,9 +80,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Assign::class;
|
||||
return [Assign::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,9 +93,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $assignNode): ?Node
|
||||
{
|
||||
if (! $assignNode instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
if ($this->propertyFetchAnalyzer->isTypesAndProperty(
|
||||
$assignNode->var,
|
||||
$this->types,
|
||||
|
@ -100,6 +100,7 @@ CODE_SAMPLE
|
|||
) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var PropertyFetch $propertyFetchNode */
|
||||
$propertyFetchNode = $assignNode->var;
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ use Rector\Rector\AbstractRector;
|
|||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @todo fix
|
||||
*/
|
||||
final class ClassReplacerRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
|
@ -44,9 +47,12 @@ final class ClassReplacerRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Name::class;
|
||||
return [Name::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,34 +60,19 @@ final class ClassReplacerRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $nameNode): ?Node
|
||||
{
|
||||
if (! $nameNode instanceof Name) {
|
||||
$resolvedNameNode = $this->resolveNameNodeFromNode($nameNode);
|
||||
if ($resolvedNameNode === null) {
|
||||
return null;
|
||||
}
|
||||
$nameNode = $this->resolveNameNodeFromNode($nameNode);
|
||||
if ($nameNode === null) {
|
||||
return null;
|
||||
}
|
||||
if (isset($this->oldToNewClasses[$nameNode->toString()]) === false) {
|
||||
return null;
|
||||
}
|
||||
if ($nameNode instanceof Name) {
|
||||
$newName = $this->resolveNewNameFromNode($nameNode);
|
||||
|
||||
$newName = $this->oldToNewClasses[$resolvedNameNode->toString()] ?? null;
|
||||
if ($newName) {
|
||||
return new FullyQualified($newName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveNewNameFromNode(Node $node): string
|
||||
{
|
||||
$nameNode = $this->resolveNameNodeFromNode($node);
|
||||
|
||||
if ($nameNode !== null) {
|
||||
return $this->oldToNewClasses[$nameNode->toString()];
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveNameNodeFromNode(Node $node): ?Name
|
||||
{
|
||||
// @todo use NodeTypeResolver?
|
||||
|
|
|
@ -73,9 +73,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Class_::class;
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,14 +86,15 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classNode): ?Node
|
||||
{
|
||||
if (! $classNode instanceof Class_ || $classNode->extends === null || $classNode->isAnonymous()) {
|
||||
if ($classNode->extends === null || $classNode->isAnonymous()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$nodeParentClassName = $this->getClassNodeParentClassName($classNode);
|
||||
if (isset($this->parentClassToTraits[$nodeParentClassName]) === false) {
|
||||
return null;
|
||||
}
|
||||
$nodeParentClassName = $this->getClassNodeParentClassName($classNode);
|
||||
|
||||
$traitNames = $this->parentClassToTraits[$nodeParentClassName];
|
||||
|
||||
// keep the Trait order the way it is in config
|
||||
|
|
|
@ -19,9 +19,12 @@ final class InArrayAndArrayKeysToArrayKeyExistsRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return FuncCall::class;
|
||||
return [FuncCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,12 +35,12 @@ final class InArrayAndArrayKeysToArrayKeyExistsRector extends AbstractRector
|
|||
if (! $this->isInArrayFunction($funcCall)) {
|
||||
return null;
|
||||
}
|
||||
/** @var FuncCall $inArrayFunction */
|
||||
$inArrayFunction = $funcCall;
|
||||
$secondArgument = $inArrayFunction->args[1]->value;
|
||||
|
||||
$secondArgument = $funcCall->args[1]->value;
|
||||
if (! $secondArgument instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Name $functionName */
|
||||
$functionName = $secondArgument->name;
|
||||
if ($functionName->toString() !== 'array_keys') {
|
||||
|
@ -58,15 +61,9 @@ final class InArrayAndArrayKeysToArrayKeyExistsRector extends AbstractRector
|
|||
return $funcCall;
|
||||
}
|
||||
|
||||
private function isInArrayFunction(Node $node): bool
|
||||
private function isInArrayFunction(FuncCall $funcCallNode): bool
|
||||
{
|
||||
if (! $node instanceof FuncCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Name $funcCallName */
|
||||
$funcCallName = $node->name;
|
||||
|
||||
$funcCallName = $funcCallNode->name;
|
||||
if (! $funcCallName instanceof Name) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -37,16 +37,6 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector
|
|||
SmallerOrEqual::class => GreaterOrEqual::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $ifValue;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $elseValue;
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition(
|
||||
|
@ -55,9 +45,12 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Ternary::class;
|
||||
return [Ternary::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,36 +58,38 @@ final class UnnecessaryTernaryExpressionRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $ternaryNode): ?Node
|
||||
{
|
||||
if (! $ternaryNode instanceof Ternary) {
|
||||
return null;
|
||||
}
|
||||
/** @var Ternary $ternaryExpression */
|
||||
$ternaryExpression = $ternaryNode;
|
||||
if (! $ternaryExpression->if instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$condition = $ternaryExpression->cond;
|
||||
if (! $condition instanceof BinaryOp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ifExpression = $ternaryExpression->if;
|
||||
$elseExpression = $ternaryExpression->else;
|
||||
if (! $ifExpression instanceof ConstFetch || ! $elseExpression instanceof ConstFetch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Identifier $ifExpressionName */
|
||||
$ifExpressionName = $ifExpression->name;
|
||||
|
||||
/** @var Identifier $elseExpressionName */
|
||||
$elseExpressionName = $elseExpression->name;
|
||||
$this->ifValue = $ifExpressionName->toLowerString();
|
||||
$this->elseValue = $elseExpressionName->toLowerString();
|
||||
if (! in_array('null', [$this->ifValue, $this->elseValue], true) === false) {
|
||||
|
||||
$ifValue = $ifExpressionName->toLowerString();
|
||||
$elseValue = $elseExpressionName->toLowerString();
|
||||
if (! in_array('null', [$ifValue, $elseValue], true) === false) {
|
||||
return null;
|
||||
}
|
||||
/** @var BinaryOp $binaryOperation */
|
||||
$binaryOperation = $ternaryNode->cond;
|
||||
|
||||
if ($this->ifValue === 'true' && $this->elseValue === 'false') {
|
||||
if ($ifValue === 'true' && $elseValue === 'false') {
|
||||
return $binaryOperation;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,6 @@ final class ClassConstantReplacerRector extends AbstractRector
|
|||
*/
|
||||
private $identifierRenamer;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $activeType;
|
||||
|
||||
/**
|
||||
* @param string[] $oldToNewConstantsByClass
|
||||
*/
|
||||
|
@ -70,9 +65,12 @@ final class ClassConstantReplacerRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassConstFetch::class;
|
||||
return [ClassConstFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,15 +78,20 @@ final class ClassConstantReplacerRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $classConstFetchNode): ?Node
|
||||
{
|
||||
$this->activeType = null;
|
||||
$activeType = null;
|
||||
foreach ($this->oldToNewConstantsByClass as $type => $oldToNewConstants) {
|
||||
$matchedType = $this->classConstAnalyzer->matchTypes($classConstFetchNode, $this->getTypes());
|
||||
if ($matchedType) {
|
||||
$this->activeType = $matchedType;
|
||||
$activeType = $matchedType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
$configuration = $this->oldToNewConstantsByClass[$this->activeType];
|
||||
|
||||
if ($activeType === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$configuration = $this->oldToNewConstantsByClass[$activeType];
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $classConstFetchNode->name;
|
||||
|
|
|
@ -56,9 +56,12 @@ final class RenameClassConstantsUseToStringsRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassConstFetch::class;
|
||||
return [ClassConstFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,9 +69,6 @@ final class RenameClassConstantsUseToStringsRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $classConstFetchNode): ?Node
|
||||
{
|
||||
if (! $classConstFetchNode instanceof ClassConstFetch) {
|
||||
return null;
|
||||
}
|
||||
$className = $this->getClassNameFromClassConstFetch($classConstFetchNode);
|
||||
if ($className !== $this->class) {
|
||||
return null;
|
||||
|
|
|
@ -59,7 +59,10 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Property::class, NullableType::class, Variable::class];
|
||||
}
|
||||
|
@ -69,27 +72,22 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($node instanceof Property) {
|
||||
if ($this->isPropertyCandidate($node) === false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (($node instanceof NullableType || $node instanceof Variable) === false) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof Property) {
|
||||
if ($node instanceof Property && $this->isPropertyCandidate($node)) {
|
||||
$this->refactorProperty($node);
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ($node instanceof NullableType) {
|
||||
$this->refactorNullableType($node);
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ($node instanceof Variable) {
|
||||
$this->refactorVariableNode($node);
|
||||
return $node;
|
||||
}
|
||||
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
|
||||
private function isPropertyCandidate(Property $propertyNode): bool
|
||||
|
|
|
@ -56,7 +56,10 @@ final class ValueObjectRemoverRector extends AbstractValueObjectRemoverRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [New_::class, Property::class, Name::class, NullableType::class];
|
||||
}
|
||||
|
@ -66,33 +69,20 @@ final class ValueObjectRemoverRector extends AbstractValueObjectRemoverRector
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($node instanceof New_) {
|
||||
if ($this->processNewCandidate($node) === false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($node instanceof Property) {
|
||||
if ($this->processPropertyCandidate($node) === false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($node instanceof Name) {
|
||||
$parentNode = $node->getAttribute(Attribute::PARENT_NODE);
|
||||
if ($parentNode instanceof Param) {
|
||||
}
|
||||
}
|
||||
if ($node instanceof NullableType === false) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof New_) {
|
||||
if ($node instanceof New_ && $this->processNewCandidate($node)) {
|
||||
return $node->args[0];
|
||||
}
|
||||
|
||||
if ($node instanceof Property) {
|
||||
if ($node instanceof Property && $this->processPropertyCandidate($node)) {
|
||||
return $this->refactorProperty($node);
|
||||
}
|
||||
|
||||
if ($node instanceof Name) {
|
||||
$parentNode = $node->getAttribute(Attribute::PARENT_NODE);
|
||||
if (! $parentNode instanceof Param) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->refactorName($node);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@ final class FunctionReplaceRector extends AbstractRector
|
|||
}
|
||||
|
||||
/**
|
||||
* future compatibility
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeType(): string
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return FuncCall::class;
|
||||
return [FuncCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,10 +53,6 @@ final class FunctionReplaceRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $node instanceof FuncCall) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
// anonymous function
|
||||
if (! $node->name instanceof Name) {
|
||||
return $node;
|
||||
|
|
|
@ -47,9 +47,12 @@ final class FunctionToMethodCallRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return FuncCall::class;
|
||||
return [FuncCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,9 +60,6 @@ final class FunctionToMethodCallRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $funcCallNode): ?Node
|
||||
{
|
||||
if (! $funcCallNode instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
if (! $funcCallNode->name instanceof Name) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -42,11 +42,11 @@ final class FunctionToStaticCallRector extends AbstractRector
|
|||
}
|
||||
|
||||
/**
|
||||
* future compatibility
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeType(): string
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return FuncCall::class;
|
||||
return [FuncCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,9 +55,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Class_::class;
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,19 +68,10 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classNode): ?Node
|
||||
{
|
||||
if (! $classNode instanceof Class_) {
|
||||
return null;
|
||||
}
|
||||
if (! $classNode->implements) {
|
||||
return null;
|
||||
}
|
||||
foreach ($classNode->implements as $implement) {
|
||||
$interface = (string) $implement->getAttribute(Attribute::RESOLVED_NAME);
|
||||
|
||||
if (array_key_exists($interface, $this->oldToNewInterfaces)) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
foreach ($classNode->implements as $key => $implement) {
|
||||
$interface = (string) $implement->getAttribute(Attribute::RESOLVED_NAME);
|
||||
|
||||
|
|
|
@ -28,11 +28,6 @@ final class GetAndSetToMethodCallRector extends AbstractRector
|
|||
*/
|
||||
private $propertyFetchAnalyzer;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $activeTransformation = [];
|
||||
|
||||
/**
|
||||
* @var ExpressionAnalyzer
|
||||
*/
|
||||
|
@ -104,9 +99,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Expression::class;
|
||||
return [Expression::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,24 +112,30 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $expressionNode): ?Node
|
||||
{
|
||||
$this->activeTransformation = [];
|
||||
$activeTransformation = null;
|
||||
$propertyFetchNode = $this->expressionAnalyzer->resolvePropertyFetch($expressionNode);
|
||||
if ($propertyFetchNode === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->typeToMethodCalls as $type => $transformation) {
|
||||
if ($this->propertyFetchAnalyzer->isMagicOnType($propertyFetchNode, $type)) {
|
||||
$this->activeTransformation = $transformation;
|
||||
$activeTransformation = $transformation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
if ($activeTransformation === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Assign $assignNode */
|
||||
$assignNode = $expressionNode->expr;
|
||||
|
||||
if ($assignNode->expr instanceof PropertyFetch) {
|
||||
/** @var PropertyFetch $propertyFetchNode */
|
||||
$propertyFetchNode = $assignNode->expr;
|
||||
$method = $this->activeTransformation['get'];
|
||||
$method = $activeTransformation['get'];
|
||||
$assignNode->expr = $this->createMethodCallNodeFromPropertyFetchNode($propertyFetchNode, $method);
|
||||
|
||||
return $expressionNode;
|
||||
|
@ -139,7 +143,7 @@ CODE_SAMPLE
|
|||
|
||||
/** @var Assign $assignNode */
|
||||
$assignNode = $expressionNode->expr;
|
||||
$method = $this->activeTransformation['set'];
|
||||
$method = $activeTransformation['set'];
|
||||
$expressionNode->expr = $this->createMethodCallNodeFromAssignNode($assignNode, $method);
|
||||
|
||||
return $expressionNode;
|
||||
|
|
|
@ -91,7 +91,10 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [String_::class, MethodCall::class];
|
||||
}
|
||||
|
@ -101,25 +104,16 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($node instanceof String_) {
|
||||
if ($this->processStringCandidate($node) === false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($node instanceof MethodCall) {
|
||||
if ($this->processMethodCallCandidate($node) === false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if ($node instanceof String_) {
|
||||
if ($node instanceof String_ && $this->processStringCandidate($node)) {
|
||||
return $this->methodCallNodeFactory->createWithVariableAndMethodName(
|
||||
$node->expr,
|
||||
$this->activeTransformation
|
||||
);
|
||||
}
|
||||
|
||||
$this->identifierRenamer->renameNode($node, $this->activeTransformation);
|
||||
if ($node instanceof MethodCall && $this->processMethodCallCandidate($node)) {
|
||||
$this->identifierRenamer->renameNode($node, $this->activeTransformation);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,10 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Isset_::class, Unset_::class];
|
||||
}
|
||||
|
@ -93,18 +96,17 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
|
|||
public function refactor(Node $issetOrUnsetNode): ?Node
|
||||
{
|
||||
$this->activeTransformation = [];
|
||||
if (! $issetOrUnsetNode instanceof Isset_ && ! $issetOrUnsetNode instanceof Unset_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($issetOrUnsetNode->vars as $var) {
|
||||
if (! $var instanceof ArrayDimFetch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->matchArrayDimFetch($var)) {
|
||||
if (! $this->matchArrayDimFetch($var)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
$method = $this->resolveMethod($issetOrUnsetNode);
|
||||
if ($method === null) {
|
||||
return $issetOrUnsetNode;
|
||||
|
|
|
@ -64,9 +64,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -83,9 +83,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Return_::class;
|
||||
return [Return_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -93,9 +93,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return MethodCall::class;
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,7 +85,10 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Identifier::class, MethodCall::class];
|
||||
}
|
||||
|
@ -95,31 +98,15 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$this->activeTypes = [];
|
||||
$matchedTypes = $this->methodCallAnalyzer->matchTypes($node, $this->getClasses());
|
||||
if ($matchedTypes) {
|
||||
$this->activeTypes = $matchedTypes;
|
||||
}
|
||||
if ($this->isMethodName($node, $this->getClasses()) === false) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof Identifier) {
|
||||
return $this->resolveIdentifier($node);
|
||||
return $this->processIdentifierNode($node);
|
||||
}
|
||||
|
||||
$oldToNewMethods = $this->matchOldToNewMethods();
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->name;
|
||||
|
||||
$methodName = $identifierNode->toString();
|
||||
if (! isset($oldToNewMethods[$methodName])) {
|
||||
return $node;
|
||||
if ($node instanceof MethodCall) {
|
||||
return $this->processMethodCall($node);
|
||||
}
|
||||
|
||||
$this->identifierRenamer->renameNode($node, $oldToNewMethods[$methodName]);
|
||||
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +163,7 @@ CODE_SAMPLE
|
|||
return true;
|
||||
}
|
||||
|
||||
private function resolveIdentifier(Identifier $node): Node
|
||||
private function resolveIdentifier(Identifier $node): Identifier
|
||||
{
|
||||
$oldToNewMethods = $this->matchOldToNewMethods();
|
||||
|
||||
|
@ -189,4 +176,44 @@ CODE_SAMPLE
|
|||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function processIdentifierNode(Identifier $identifierNode): ?Identifier
|
||||
{
|
||||
$this->activeTypes = [];
|
||||
|
||||
$matchedTypes = $this->methodCallAnalyzer->matchTypes($identifierNode, $this->getClasses());
|
||||
|
||||
if ($matchedTypes) {
|
||||
$this->activeTypes = $matchedTypes;
|
||||
}
|
||||
|
||||
if ($this->isMethodName($identifierNode, $this->getClasses()) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->resolveIdentifier($identifierNode);
|
||||
}
|
||||
|
||||
private function processMethodCall(MethodCall $node): ?MethodCall
|
||||
{
|
||||
$this->activeTypes = [];
|
||||
$matchedTypes = $this->methodCallAnalyzer->matchTypes($node, $this->getClasses());
|
||||
if ($matchedTypes) {
|
||||
$this->activeTypes = $matchedTypes;
|
||||
}
|
||||
|
||||
$oldToNewMethods = $this->matchOldToNewMethods();
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->name;
|
||||
|
||||
$methodName = $identifierNode->toString();
|
||||
if (! isset($oldToNewMethods[$methodName])) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
$this->identifierRenamer->renameNode($node, $oldToNewMethods[$methodName]);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,10 @@ final class StaticMethodNameReplacerRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Identifier::class, StaticCall::class];
|
||||
}
|
||||
|
@ -84,35 +87,15 @@ final class StaticMethodNameReplacerRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$this->activeTypes = [];
|
||||
$matchedTypes = $this->staticMethodCallAnalyzer->matchTypes($node, $this->getClasses());
|
||||
if ($matchedTypes) {
|
||||
$this->activeTypes = $matchedTypes;
|
||||
}
|
||||
if ($this->isMethodName($node, $this->getClasses()) === false) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof Identifier) {
|
||||
return $this->resolveIdentifier($node);
|
||||
return $this->processIdentifierNode($node);
|
||||
}
|
||||
|
||||
$oldToNewMethods = $this->matchOldToNewMethods();
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->name;
|
||||
|
||||
$methodName = $identifierNode->toString();
|
||||
if (! isset($oldToNewMethods[$methodName])) {
|
||||
return $node;
|
||||
if ($node instanceof StaticCall) {
|
||||
return $this->processStaticCallNode($node);
|
||||
}
|
||||
|
||||
if ($node instanceof StaticCall && $this->isClassRename($oldToNewMethods)) {
|
||||
return $this->resolveClassRename($node, $oldToNewMethods, $methodName);
|
||||
}
|
||||
|
||||
$this->identifierRenamer->renameNode($node, $oldToNewMethods[$methodName]);
|
||||
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,7 +162,7 @@ final class StaticMethodNameReplacerRector extends AbstractRector
|
|||
return true;
|
||||
}
|
||||
|
||||
private function resolveIdentifier(Identifier $node): Node
|
||||
private function resolveIdentifier(Identifier $node): Identifier
|
||||
{
|
||||
$oldToNewMethods = $this->matchOldToNewMethods();
|
||||
|
||||
|
@ -205,4 +188,46 @@ final class StaticMethodNameReplacerRector extends AbstractRector
|
|||
|
||||
return $staticCallNode;
|
||||
}
|
||||
|
||||
private function processIdentifierNode(Identifier $node): ?Identifier
|
||||
{
|
||||
$this->activeTypes = [];
|
||||
$matchedTypes = $this->staticMethodCallAnalyzer->matchTypes($node, $this->getClasses());
|
||||
if ($matchedTypes) {
|
||||
$this->activeTypes = $matchedTypes;
|
||||
}
|
||||
|
||||
if ($this->isMethodName($node, $this->getClasses()) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->resolveIdentifier($node);
|
||||
}
|
||||
|
||||
private function processStaticCallNode(StaticCall $node): ?Node
|
||||
{
|
||||
$this->activeTypes = [];
|
||||
$matchedTypes = $this->staticMethodCallAnalyzer->matchTypes($node, $this->getClasses());
|
||||
if ($matchedTypes) {
|
||||
$this->activeTypes = $matchedTypes;
|
||||
}
|
||||
|
||||
$oldToNewMethods = $this->matchOldToNewMethods();
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->name;
|
||||
|
||||
$methodName = $identifierNode->toString();
|
||||
if (! isset($oldToNewMethods[$methodName])) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ($this->isClassRename($oldToNewMethods)) {
|
||||
return $this->resolveClassRename($node, $oldToNewMethods, $methodName);
|
||||
}
|
||||
|
||||
$this->identifierRenamer->renameNode($node, $oldToNewMethods[$methodName]);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,17 @@ final class NamespaceReplacerRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Node::class;
|
||||
return [Namespace_::class, Use_::class, Name::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Namespace_|Use_|Name $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$name = $this->resolveNameFromNode($node);
|
||||
|
|
|
@ -72,7 +72,10 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Name::class, Identifier::class];
|
||||
}
|
||||
|
@ -86,14 +89,15 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector
|
|||
if ($name === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (in_array($name, $this->excludedClasses, true)) {
|
||||
return null;
|
||||
}
|
||||
foreach ($this->pseudoNamespacePrefixes as $pseudoNamespacePrefix) {
|
||||
if (Strings::startsWith($name, $pseudoNamespacePrefix)) {
|
||||
}
|
||||
|
||||
if (! $this->isNamespaceMatch($name)) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
$oldName = $this->resolveNameFromNode($nameOrIdentifierNode);
|
||||
|
||||
$newNameParts = explode('_', $oldName);
|
||||
|
@ -151,4 +155,15 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function isNamespaceMatch(string $name): bool
|
||||
{
|
||||
foreach ($this->pseudoNamespacePrefixes as $pseudoNamespacePrefix) {
|
||||
if (Strings::startsWith($name, $pseudoNamespacePrefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,9 +67,12 @@ final class PropertyNameReplacerRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return PropertyFetch::class;
|
||||
return [PropertyFetch::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,10 +82,11 @@ final class PropertyNameReplacerRector extends AbstractRector
|
|||
{
|
||||
$this->activeTypes = [];
|
||||
$matchedTypes = $this->propertyFetchAnalyzer->matchTypes($propertyFetchNode, $this->getClasses());
|
||||
|
||||
if ($matchedTypes) {
|
||||
$this->activeTypes = $matchedTypes;
|
||||
}
|
||||
return null;
|
||||
|
||||
$oldToNewProperties = $this->matchOldToNewProperties();
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
|
|
|
@ -81,9 +81,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Assign::class;
|
||||
return [Assign::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,9 +94,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $assignNode): ?Node
|
||||
{
|
||||
if (! $assignNode instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
// setter
|
||||
if ($assignNode->var instanceof PropertyFetch) {
|
||||
if ($this->processPropertyFetchCandidate($assignNode->var, 'set') === false) {
|
||||
|
@ -106,7 +106,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
// setter
|
||||
if ($assignNode->var instanceof PropertyFetch) {
|
||||
$args = $this->nodeFactory->createArgs([$assignNode->expr]);
|
||||
|
|
|
@ -23,11 +23,6 @@ final class StaticCallToFunctionRector extends AbstractRector
|
|||
*/
|
||||
private $staticMethodCallAnalyzer;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $activeStaticCall;
|
||||
|
||||
/**
|
||||
* @param string[] $staticCallToFunction
|
||||
*/
|
||||
|
@ -52,9 +47,12 @@ final class StaticCallToFunctionRector extends AbstractRector
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return StaticCall::class;
|
||||
return [StaticCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,18 +60,20 @@ final class StaticCallToFunctionRector extends AbstractRector
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $node instanceof StaticCall) {
|
||||
return null;
|
||||
}
|
||||
$staticCalls = array_keys($this->staticCallToFunction);
|
||||
$activeStaticCall = null;
|
||||
foreach ($staticCalls as $staticCall) {
|
||||
[$class, $method] = explode('::', $staticCall);
|
||||
if ($this->staticMethodCallAnalyzer->isTypeAndMethod($node, $class, $method)) {
|
||||
$this->activeStaticCall = $staticCall;
|
||||
$activeStaticCall = $staticCall;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
$newFunctionName = $this->staticCallToFunction[$this->activeStaticCall];
|
||||
|
||||
if (! isset($this->staticCallToFunction[$activeStaticCall])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$newFunctionName = $this->staticCallToFunction[$activeStaticCall];
|
||||
|
||||
return new FuncCall(new FullyQualified($newFunctionName), $node->args);
|
||||
}
|
||||
|
|
|
@ -95,9 +95,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassMethod::class;
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,9 +108,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classMethodNode): ?Node
|
||||
{
|
||||
if (! $classMethodNode instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
/** @var ClassLike $classNode */
|
||||
$classNode = $classMethodNode->getAttribute(Attribute::CLASS_NODE);
|
||||
$classNodeTypes = $this->nodeTypeResolver->resolve($classNode);
|
||||
|
|
|
@ -80,9 +80,12 @@ CODE_SAMPLE
|
|||
]);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassMethod::class;
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,9 +93,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classMethodNode): ?Node
|
||||
{
|
||||
if (! $classMethodNode instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
/** @var ClassLike $classNode */
|
||||
$classNode = $classMethodNode->getAttribute(Attribute::CLASS_NODE);
|
||||
$classNodeTypes = $this->nodeTypeResolver->resolve($classNode);
|
||||
|
|
|
@ -72,9 +72,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassConst::class;
|
||||
return [ClassConst::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,9 +85,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classConstantNode): ?Node
|
||||
{
|
||||
if (! $classConstantNode instanceof ClassConst) {
|
||||
return null;
|
||||
}
|
||||
// doesn't have a parent class
|
||||
if (! $classConstantNode->hasAttribute(Attribute::PARENT_CLASS_NAME)) {
|
||||
return null;
|
||||
|
|
|
@ -79,9 +79,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return ClassMethod::class;
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,9 +92,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $classMethodNode): ?Node
|
||||
{
|
||||
if (! $classMethodNode instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
// doesn't have a parent class
|
||||
if (! $classMethodNode->hasAttribute(Attribute::PARENT_CLASS_NAME)) {
|
||||
return null;
|
||||
|
|
|
@ -71,9 +71,12 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return Property::class;
|
||||
return [Property::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,9 +84,6 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $propertyNode): ?Node
|
||||
{
|
||||
if (! $propertyNode instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
// doesn't have a parent class
|
||||
if (! $propertyNode->hasAttribute(Attribute::PARENT_CLASS_NAME)) {
|
||||
return null;
|
||||
|
|
|
@ -5,6 +5,9 @@ namespace Rector\Tests\Rector\Annotation\AnnotationReplacerRector;
|
|||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
/**
|
||||
* @see \Rector\Rector\Annotation\AnnotationReplacerRector
|
||||
*/
|
||||
final class ScenarioToTestAnnotationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@ final class ClassReplacerRectorTest extends AbstractRectorTestCase
|
|||
|
||||
public function provideWrongToFixedFiles(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
||||
// yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
|
||||
}
|
||||
|
||||
|
|
|
@ -3,3 +3,4 @@ services:
|
|||
$oldToNewClasses:
|
||||
'SomeNamespace\OldClass': 'Rector\Tests\Rector\Class_\ClassReplacerRector\Source\NewClass'
|
||||
'PhpParser\BuilderAbstract': 'PhpParser\Builder'
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
|||
|
||||
/**
|
||||
* @covers \Rector\Rector\DomainDrivenDesign\ValueObjectRemover\ValueObjectRemoverRector
|
||||
* @covers \Rector\Rector\DomainDrivenDesign\ValueObjectRemover\ValueObjectRemoverDocBlockRector
|
||||
*/
|
||||
final class ValueObjectRemoverRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user