mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-11 11:11:12 +01:00
[TypeDeclaration] Skip exception on void (#6182)
This commit is contained in:
parent
aee2cb0f07
commit
4dfd6df447
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
|
||||
final class SkipException
|
||||
{
|
||||
public function getValues()
|
||||
{
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user