[TypeDeclaration] Skip exception on void (#6182)

This commit is contained in:
Tomas Votruba 2021-04-20 21:50:10 +02:00 committed by GitHub
parent aee2cb0f07
commit 4dfd6df447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 5 deletions

View File

@ -0,0 +1,11 @@
<?php
use Rector\Core\Exception\ShouldNotHappenException;
final class SkipException
{
public function getValues()
{
throw new ShouldNotHappenException();
}
}

View File

@ -74,7 +74,7 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::SCALAR_TYPES)) {
if (! $this->isAtLeastPhpVersion(PhpVersionFeature::VOID_TYPE)) {
return null;
}
@ -90,10 +90,7 @@ CODE_SAMPLE
return null;
}
if ($this->isAtLeastPhpVersion(PhpVersionFeature::VOID_TYPE)) {
$node->returnType = new Identifier('void');
}
$node->returnType = new Identifier('void');
return $node;
}
}

View File

@ -41,6 +41,10 @@ final class SilentVoidResolver
return false;
}
if ($this->hasNeverType($functionLike)) {
return false;
}
if ($this->betterNodeFinder->hasInstancesOf((array) $functionLike->stmts, [Yield_::class])) {
return false;
}
@ -133,4 +137,13 @@ final class SilentVoidResolver
return true;
}
/**
* @see https://phpstan.org/writing-php-code/phpdoc-types#bottom-type
* @param ClassMethod|Closure|Function_ $functionLike
*/
private function hasNeverType(FunctionLike $functionLike): bool
{
return $this->betterNodeFinder->hasInstancesOf($functionLike, [Throw_::class]);
}
}