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 a956f09
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 60 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.

27 changes: 0 additions & 27 deletions rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,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 +138,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 a956f09

Please sign in to comment.