Skip to content

Commit

Permalink
Remove ReturnTypeDeclarationReturnTypeInferer (#3117)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 28, 2022
1 parent 742378f commit 183bb5b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 83 deletions.
6 changes: 3 additions & 3 deletions rules/TypeDeclaration/FunctionLikeReturnTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Rector\TypeDeclaration;

use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\StaticTypeMapper\StaticTypeMapper;
Expand All @@ -16,9 +16,9 @@ public function __construct(
) {
}

public function resolveFunctionLikeReturnTypeToPHPStanType(FunctionLike $functionLike): Type
public function resolveFunctionLikeReturnTypeToPHPStanType(ClassMethod $classMethod): Type
{
$functionReturnType = $functionLike->getReturnType();
$functionReturnType = $classMethod->getReturnType();
if ($functionReturnType === null) {
return new MixedType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use Rector\TypeDeclaration\TypeAnalyzer\AdvancedArrayAnalyzer;
use Rector\TypeDeclaration\TypeAnalyzer\IterableTypeAnalyzer;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer\ReturnTypeDeclarationReturnTypeInfererTypeInferer;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -121,10 +120,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
return null;
}

$inferredReturnType = $this->returnTypeInferer->inferFunctionLikeWithExcludedInferers(
$node,
[ReturnTypeDeclarationReturnTypeInfererTypeInferer::class]
);
$inferredReturnType = $this->returnTypeInferer->inferFunctionLike($node);

$inferredReturnType = $this->normalizeTypeToRespectArrayScalarType->normalizeToArray(
$inferredReturnType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Rector\TypeDeclaration\TypeAlreadyAddedChecker\ReturnTypeAlreadyAddedChecker;
use Rector\TypeDeclaration\TypeAnalyzer\ObjectTypeComparator;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer\ReturnTypeDeclarationReturnTypeInfererTypeInferer;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnVendorLockResolver;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand Down Expand Up @@ -108,10 +107,7 @@ public function refactor(Node $node): ?Node
return null;
}

$inferedReturnType = $this->returnTypeInferer->inferFunctionLikeWithExcludedInferers(
$node,
[ReturnTypeDeclarationReturnTypeInfererTypeInferer::class]
);
$inferedReturnType = $this->returnTypeInferer->inferFunctionLike($node);

if ($inferedReturnType instanceof MixedType || $inferedReturnType instanceof NonExistingObjectType) {
return null;
Expand Down
30 changes: 0 additions & 30 deletions rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ public function __construct(

public function inferFunctionLike(ClassMethod|Function_|Closure $functionLike): Type
{
return $this->inferFunctionLikeWithExcludedInferers($functionLike, []);
}

/**
* @param array<class-string<ReturnTypeInfererInterface>> $excludedInferers
*/
public function inferFunctionLikeWithExcludedInferers(
ClassMethod|Function_|Closure $functionLike,
array $excludedInferers
): Type {
$isSupportedStaticReturnType = $this->phpVersionProvider->isAtLeastPhpVersion(
PhpVersionFeature::STATIC_RETURN_TYPE
);
Expand All @@ -90,10 +80,6 @@ public function inferFunctionLikeWithExcludedInferers(
}

foreach ($this->returnTypeInferers as $returnTypeInferer) {
if ($this->shouldSkipExcludedTypeInferer($returnTypeInferer, $excludedInferers)) {
continue;
}

$originalType = $returnTypeInferer->inferFunctionLike($functionLike);
if ($originalType instanceof MixedType) {
continue;
Expand Down Expand Up @@ -269,22 +255,6 @@ private function isStaticType(Type $type): bool
return $type->getClassName() === ObjectReference::STATIC;
}

/**
* @param array<class-string<ReturnTypeInfererInterface>> $excludedInferers
*/
private function shouldSkipExcludedTypeInferer(
ReturnTypeInfererInterface $returnTypeInferer,
array $excludedInferers
): bool {
foreach ($excludedInferers as $excludedInferer) {
if (is_a($returnTypeInferer, $excludedInferer)) {
return true;
}
}

return false;
}

private function resolveUnionStaticTypes(UnionType $unionType, bool $isSupportedStaticReturnType): UnionType|null
{
$resolvedTypes = [];
Expand Down

This file was deleted.

0 comments on commit 183bb5b

Please sign in to comment.