From b48737ab076f6f35bb1efd03648e5fb73736193a Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Mon, 18 May 2020 22:42:20 +0200 Subject: [PATCH] fix missing doc for property type infering --- .../src/Rector/Property/PropertyTypeDeclarationRector.php | 4 ++-- .../PropertyTypeInferer/VarDocPropertyTypeInferer.php | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rules/type-declaration/src/Rector/Property/PropertyTypeDeclarationRector.php b/rules/type-declaration/src/Rector/Property/PropertyTypeDeclarationRector.php index 8271bfed7119..282f85ac875b 100644 --- a/rules/type-declaration/src/Rector/Property/PropertyTypeDeclarationRector.php +++ b/rules/type-declaration/src/Rector/Property/PropertyTypeDeclarationRector.php @@ -53,9 +53,9 @@ public function refactor(Node $node): ?Node } // is already set - /** @var PhpDocInfo $phpDocInfo */ + /** @var PhpDocInfo|null $phpDocInfo */ $phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO); - if (! $phpDocInfo->getVarType() instanceof MixedType) { + if ($phpDocInfo !== null && ! $phpDocInfo->getVarType() instanceof MixedType) { return null; } diff --git a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/VarDocPropertyTypeInferer.php b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/VarDocPropertyTypeInferer.php index 85f94f8f7597..27ec8040c867 100644 --- a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/VarDocPropertyTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/VarDocPropertyTypeInferer.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer; use PhpParser\Node\Stmt\Property; +use PHPStan\Type\MixedType; use PHPStan\Type\Type; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -14,8 +15,11 @@ final class VarDocPropertyTypeInferer implements PropertyTypeInfererInterface { public function inferProperty(Property $property): Type { - /** @var PhpDocInfo $phpDocInfo */ + /** @var PhpDocInfo|null $phpDocInfo */ $phpDocInfo = $property->getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return new MixedType(); + } return $phpDocInfo->getVarType(); }