Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-apply isVoid() (#3574) #3586

Merged
merged 4 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rules/Php72/NodeFactory/AnonymousFunctionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down