Skip to content

Commit

Permalink
Re-apply isVoid() (#3574) (#3586)
Browse files Browse the repository at this point in the history
* Use isVoid() (#3574)

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

---------

Co-authored-by: Yassine Guedidi <yassine@guedidi.com>
Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
3 people committed Apr 8, 2023
1 parent 77a3c02 commit a6ca5a0
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
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
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
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
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
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
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
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

0 comments on commit a6ca5a0

Please sign in to comment.