mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 03:40:50 +00:00
Fixing rules return values (take 2) (#1880)
* Fixing rules return values (take 2) * fix on ReturnNeverTypeRector * fix on PropertyAssignToMethodCallRector * fix on AddInterfaceByParentRector * fix on AddInterfaceByTraitRector * fix on MergeInterfacesRector * fix on CompleteImportForPartialAnnotationRector * fix on RenameAnnotationRector * phpstan * [ci-review] Rector Rectify * fix on RemoveFuncCallRector Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
d93639c5f4
commit
2604c7675c
|
@ -98,6 +98,10 @@ CODE_SAMPLE
|
|||
|
||||
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $constType);
|
||||
|
||||
if (! $phpDocInfo->hasChanged()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$hasChanged = false;
|
||||
foreach ($this->removedFunctionArguments as $removedFunctionArgument) {
|
||||
if (! $this->isName($node->name, $removedFunctionArgument->getFunction())) {
|
||||
continue;
|
||||
|
@ -69,9 +70,14 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$this->nodeRemover->removeArg($node, $position);
|
||||
$hasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $hasChanged) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,10 +74,13 @@ CODE_SAMPLE
|
|||
|
||||
if ($removeFuncCall->getArgumentPositionAndValues() === []) {
|
||||
$this->removeNode($node);
|
||||
return null;
|
||||
return $node;
|
||||
}
|
||||
|
||||
$this->refactorFuncCallsWithPositions($node, $removeFuncCall);
|
||||
$removedFuncCall = $this->refactorFuncCallsWithPositions($node, $removeFuncCall);
|
||||
if ($removedFuncCall instanceof FuncCall) {
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -92,7 +95,7 @@ CODE_SAMPLE
|
|||
$this->removeFuncCalls = $configuration;
|
||||
}
|
||||
|
||||
private function refactorFuncCallsWithPositions(FuncCall $funcCall, RemoveFuncCall $removeFuncCall): void
|
||||
private function refactorFuncCallsWithPositions(FuncCall $funcCall, RemoveFuncCall $removeFuncCall): ?FuncCall
|
||||
{
|
||||
foreach ($removeFuncCall->getArgumentPositionAndValues() as $argumentPosition => $values) {
|
||||
if (! $this->isArgumentPositionValueMatch($funcCall, $argumentPosition, $values)) {
|
||||
|
@ -101,8 +104,11 @@ CODE_SAMPLE
|
|||
|
||||
if ($this->breakingRemovalGuard->isLegalNodeRemoval($funcCall)) {
|
||||
$this->removeNode($funcCall);
|
||||
return $funcCall;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,6 +92,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$hasChanged = false;
|
||||
|
||||
foreach ($this->renameAnnotations as $renameAnnotation) {
|
||||
if ($renameAnnotation instanceof RenameAnnotationByType && ! $this->isObjectType(
|
||||
|
@ -106,6 +107,11 @@ CODE_SAMPLE
|
|||
$renameAnnotation->getOldAnnotation(),
|
||||
$renameAnnotation->getNewAnnotation()
|
||||
);
|
||||
$hasChanged = true;
|
||||
}
|
||||
|
||||
if (! $hasChanged) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
|
|
@ -82,7 +82,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$printedClass = $this->print($class);
|
||||
|
||||
$hasChanged = false;
|
||||
foreach ($this->useImportsToRestore as $useImportToRestore) {
|
||||
$annotationToSeek = '#\*\s+\@' . $useImportToRestore->getAlias() . '#';
|
||||
if (! StringUtils::isMatch($printedClass, $annotationToSeek)) {
|
||||
|
@ -90,6 +90,11 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$node = $this->addImportToNamespaceIfMissing($node, $useImportToRestore);
|
||||
$hasChanged = true;
|
||||
}
|
||||
|
||||
if (! $hasChanged) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
|
|
@ -82,7 +82,7 @@ CODE_SAMPLE
|
|||
);
|
||||
}
|
||||
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -64,19 +64,13 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
/** @var Scope $scope */
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
$parentClassReflection = $this->resolveParentClassReflection($node);
|
||||
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (! $classReflection instanceof ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parentClassReflection = $classReflection->getParentClass();
|
||||
if (! $parentClassReflection instanceof ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hasChanged = false;
|
||||
foreach ($this->interfaceByParent as $parentName => $interfaceName) {
|
||||
if ($parentName !== $parentClassReflection->getName()) {
|
||||
continue;
|
||||
|
@ -89,6 +83,11 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$node->implements[] = new FullyQualified($interfaceName);
|
||||
$hasChanged = true;
|
||||
}
|
||||
|
||||
if (! $hasChanged) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
@ -104,4 +103,17 @@ CODE_SAMPLE
|
|||
|
||||
$this->interfaceByParent = $configuration;
|
||||
}
|
||||
|
||||
private function resolveParentClassReflection(Class_ $class): ?ClassReflection
|
||||
{
|
||||
/** @var Scope $scope */
|
||||
$scope = $class->getAttribute(AttributeKey::SCOPE);
|
||||
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if (! $classReflection instanceof ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $classReflection->getParentClass();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$hasChanged = false;
|
||||
foreach ($this->interfaceByTrait as $traitName => $interfaceName) {
|
||||
if (! $classReflection->hasTraitUse($traitName)) {
|
||||
continue;
|
||||
|
@ -83,6 +84,11 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$node->implements[] = new FullyQualified($interfaceName);
|
||||
$hasChanged = true;
|
||||
}
|
||||
|
||||
if (! $hasChanged) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
|
|
@ -67,6 +67,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$hasChanged = false;
|
||||
foreach ($node->implements as $key => $implement) {
|
||||
$oldInterfaces = array_keys($this->oldToNewInterfaces);
|
||||
if (! $this->isNames($implement, $oldInterfaces)) {
|
||||
|
@ -75,6 +76,11 @@ CODE_SAMPLE
|
|||
|
||||
$interface = $this->getName($implement);
|
||||
$node->implements[$key] = new Name($this->oldToNewInterfaces[$interface]);
|
||||
$hasChanged = true;
|
||||
}
|
||||
|
||||
if (! $hasChanged) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->makeImplementsUnique($node);
|
||||
|
|
|
@ -90,7 +90,11 @@ CODE_SAMPLE
|
|||
} else {
|
||||
// static anlysis based never type
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, new NeverType());
|
||||
$hasChanged = $this->phpDocTypeChanger->changeReturnType($phpDocInfo, new NeverType());
|
||||
|
||||
if (! $hasChanged) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
|
Loading…
Reference in New Issue
Block a user