mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
[TypeDeclaration] Skip array shrapnels (#5016)
* [TypeDeclaration] Skip array shrapnels * [ci-review] Rector Rectify Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
parent
305388d45d
commit
96ad185d37
@ -6,6 +6,9 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\ClassStringType;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
@ -158,6 +161,10 @@ CODE_SAMPLE
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasArrayShapeNode($classMethod)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$currentPhpDocReturnType = $this->getNodeReturnPhpDocType($classMethod);
|
||||
if ($currentPhpDocReturnType instanceof ArrayType && $currentPhpDocReturnType->getItemType() instanceof MixedType) {
|
||||
return true;
|
||||
@ -303,4 +310,24 @@ CODE_SAMPLE
|
||||
$currentReturnType = $this->getNodeReturnPhpDocType($classMethod);
|
||||
return $currentReturnType instanceof ArrayType;
|
||||
}
|
||||
|
||||
private function hasArrayShapeNode(ClassMethod $classMethod): bool
|
||||
{
|
||||
/** @var PhpDocInfo|null $phpDocInfo */
|
||||
$phpDocInfo = $classMethod->getAttribute(AttributeKey::PHP_DOC_INFO);
|
||||
if (! $phpDocInfo instanceof PhpDocInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue();
|
||||
if (! $attributeAwareReturnTagValueNode instanceof ReturnTagValueNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $attributeAwareReturnTagValueNode->type instanceof ArrayTypeNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $attributeAwareReturnTagValueNode->type->type instanceof ArrayShapeNode;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user