Skip to content

Commit

Permalink
Use isVoid() (#3574)
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi committed Apr 8, 2023
1 parent aa73118 commit 7611dcb
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 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 @@ -176,7 +176,7 @@ private function shouldSkipHasChildHasReturnType(array $childrenClassReflections
}

$childReturnType = $this->returnTypeInferer->inferFunctionLike($method);
if ($returnType instanceof VoidType && ! $childReturnType instanceof VoidType) {
if ($returnType->isVoid()->yes() && ! $childReturnType->isVoid()->yes()) {
return true;
}
}
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 @@ -53,7 +53,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 @@ -150,7 +150,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 +169,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 7611dcb

Please sign in to comment.