Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 6, 2023
1 parent 9f320ce commit d416537
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Rector\Core\Exception\ShouldNotHappenException;

final class SkipException
{
public function getValues()
{
throw new ShouldNotHappenException();
}
}
-----
<?php

use Rector\Core\Exception\ShouldNotHappenException;

final class SkipException
{
public function getValues(): void
{
throw new ShouldNotHappenException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector\Fixture;

final class ExitMethod
{
protected function getValues()
{
exit();
}
}
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector\Fixture;

final class ExitMethod
{
protected function getValues(): void
{
exit();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

32 changes: 0 additions & 32 deletions rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\FunctionLike;
Expand All @@ -18,19 +17,15 @@
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\Throw_;
use PhpParser\Node\Stmt\TryCatch;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\NeverType;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;

final class SilentVoidResolver
{
public function __construct(
private readonly BetterNodeFinder $betterNodeFinder,
private readonly ReflectionResolver $reflectionResolver,
private readonly NodeTypeResolver $nodeTypeResolver,
) {
}

Expand All @@ -41,10 +36,6 @@ public function hasExclusiveVoid(ClassMethod | Closure | Function_ $functionLike
return false;
}

if ($this->hasNeverType($functionLike)) {
return false;
}

if ($this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($functionLike, Yield_::class)) {
return false;
}
Expand Down Expand Up @@ -142,29 +133,6 @@ private function isTryCatchAlwaysReturn(TryCatch $tryCatch): bool
return true;
}

/**
* @see https://phpstan.org/writing-php-code/phpdoc-types#bottom-type
*/
private function hasNeverType(ClassMethod | Closure | Function_ $functionLike): bool
{
// look for top-level never returning statements
foreach((array) $functionLike->getStmts() as $stmt) {
if ($stmt instanceof Throw_) {
return true;
}

if ($stmt instanceof Expression) {
$exprType = $this->nodeTypeResolver->getNativeType($stmt->expr);
if ($exprType instanceof NeverType) {
return true;
}
}

}

return false;
}

private function resolveReturnCount(Switch_ $switch): int
{
$casesWithReturnCount = 0;
Expand Down

0 comments on commit d416537

Please sign in to comment.