Skip to content

Commit

Permalink
[TypeDeclaration] Deprecate unreliable AddArrayReturnDocTypeRector, u…
Browse files Browse the repository at this point in the history
…sed split strict typed rules instead (#3133)
  • Loading branch information
TomasVotruba authored Nov 30, 2022
1 parent 36e9b6c commit 64c03bd
Show file tree
Hide file tree
Showing 88 changed files with 6 additions and 3,162 deletions.
2 changes: 0 additions & 2 deletions config/set/type-declaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeBasedOnPHPUnitDataProviderRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeFromPropertyTypeRector;
Expand Down Expand Up @@ -38,7 +37,6 @@
$rectorConfig->rules([
AddClosureReturnTypeRector::class,
AddArrowFunctionReturnTypeRector::class,
AddArrayReturnDocTypeRector::class,
ParamTypeByMethodCallTypeRector::class,
TypedPropertyFromAssignsRector::class,
ReturnAnnotationIncorrectNullableRector::class,
Expand Down
86 changes: 0 additions & 86 deletions packages/StaticTypeMapper/PhpDoc/CustomPHPStanDetector.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@
use PhpParser\Node\Stmt\Return_;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\VoidType;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\StaticTypeMapper\PhpDoc\CustomPHPStanDetector;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;

final class ClassMethodReturnTypeOverrideGuard
Expand All @@ -40,7 +34,6 @@ public function __construct(
private readonly BetterNodeFinder $betterNodeFinder,
private readonly AstResolver $astResolver,
private readonly ReflectionResolver $reflectionResolver,
private readonly CustomPHPStanDetector $customPHPStanDetector,
private readonly ReturnTypeInferer $returnTypeInferer
) {
}
Expand Down Expand Up @@ -78,28 +71,6 @@ public function shouldSkipClassMethod(ClassMethod $classMethod): bool
return $this->hasClassMethodExprReturn($classMethod);
}

public function shouldSkipClassMethodOldTypeWithNewType(
Type $oldType,
Type $newType,
ClassMethod $classMethod
): bool {
if ($this->customPHPStanDetector->isCustomType($oldType, $classMethod)) {
return true;
}

if ($oldType instanceof MixedType) {
return false;
}

// new generic string type is more advanced than old array type
if ($this->isFirstArrayTypeMoreAdvanced($oldType, $newType)) {
return false;
}

return $oldType->isSuperTypeOf($newType)
->yes();
}

/**
* @param ClassReflection[] $childrenClassReflections
*/
Expand Down Expand Up @@ -169,21 +140,4 @@ static function (Node $node): bool {
}
);
}

private function isFirstArrayTypeMoreAdvanced(Type $oldType, Type $newType): bool
{
if (! $oldType instanceof ArrayType) {
return false;
}

if (! $newType instanceof ArrayType) {
return false;
}

if (! $oldType->getItemType() instanceof StringType) {
return false;
}

return $newType->getItemType() instanceof GenericClassStringType;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 64c03bd

Please sign in to comment.