diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php index 249df882835..a73769fba13 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php @@ -190,7 +190,7 @@ private function resolveNullableType(NullableType $nullableType): null|NullableT private function mapNullabledType(Type $nullabledType, string $typeKind): ?Node { // void cannot be nullable - if ($nullabledType instanceof VoidType) { + if ($nullabledType->isVoid()->yes()) { return null; } diff --git a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php index d068d59b067..77a9eafec59 100644 --- a/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php +++ b/packages/VendorLocker/NodeVendorLocker/ClassMethodReturnTypeOverrideGuard.php @@ -14,7 +14,6 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\MixedType; -use PHPStan\Type\VoidType; use Rector\Core\FileSystem\FilePathHelper; use Rector\Core\PhpParser\AstResolver; use Rector\Core\PhpParser\Node\BetterNodeFinder; @@ -176,9 +175,15 @@ private function shouldSkipHasChildHasReturnType(array $childrenClassReflections } $childReturnType = $this->returnTypeInferer->inferFunctionLike($method); - if ($returnType instanceof VoidType && ! $childReturnType instanceof VoidType) { - return true; + if (!$returnType->isVoid()->yes()) { + continue; } + + if ($childReturnType->isVoid()->yes()) { + continue; + } + + return true; } return false; diff --git a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php index 43830a62a2c..20a6717cf39 100644 --- a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php +++ b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php @@ -401,7 +401,7 @@ private function resolveStmts( FunctionVariantWithPhpDocs $functionVariantWithPhpDocs, StaticCall|MethodCall $innerMethodCall ): array { - if ($functionVariantWithPhpDocs->getReturnType() instanceof VoidType) { + if ($functionVariantWithPhpDocs->getReturnType()->isVoid()->yes()) { return [new Expression($innerMethodCall)]; } diff --git a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php index 6d89b3ee45e..af3fc71dc88 100644 --- a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php +++ b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php @@ -6,7 +6,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\ArrowFunction; -use PHPStan\Type\VoidType; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; @@ -53,7 +52,7 @@ public function refactor(Node $node): ?Node $type = $this->getType($node->expr); - if ($type instanceof VoidType) { + if ($type->isVoid()->yes()) { return null; } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php index 9d4cef82c87..b33f93d85cc 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php @@ -20,7 +20,6 @@ use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\UnionType; -use PHPStan\Type\VoidType; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; @@ -150,7 +149,7 @@ private function processArrowFunction(ArrowFunction $arrowFunction): ?ArrowFunct $resolvedType = $this->nodeTypeResolver->getType($arrowFunction->expr); // void type is not accepted for arrow functions - https://www.php.net/manual/en/functions.arrow.php#125673 - if ($resolvedType instanceof VoidType) { + if ($resolvedType->isVoid()->yes()) { return null; } @@ -169,7 +168,7 @@ private function isUnionPossibleReturnsVoid(ClassMethod | Function_ | Closure $n $inferReturnType = $this->returnTypeInferer->inferFunctionLike($node); if ($inferReturnType instanceof UnionType) { foreach ($inferReturnType->getTypes() as $type) { - if ($type instanceof VoidType) { + if ($type->isVoid()->yes()) { return true; } } diff --git a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php index 92dec6dec31..3ae8c01e70c 100644 --- a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php @@ -122,7 +122,7 @@ private function resolveTypeWithVoidHandling( ClassMethod|Function_|Closure|ArrowFunction $functionLike, Type $resolvedType ): Type { - if ($resolvedType instanceof VoidType) { + if ($resolvedType->isVoid()->yes()) { if ($functionLike instanceof ArrowFunction) { return new MixedType(); } diff --git a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php index d9ceabc045a..69d6b453b4b 100644 --- a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php @@ -170,7 +170,7 @@ private function correctWithNestedType(Type $resolvedType, Return_ $return, Func $correctedType = $this->inferFromReturnedMethodCall($return, $functionLike); // override only if has some extra value - if (! $correctedType instanceof MixedType && ! $correctedType instanceof VoidType) { + if (! $correctedType instanceof MixedType && ! $correctedType->isVoid()->yes()) { return $correctedType; } }