[TryCatch] Try/Catch with filled Finally can not be dead (#4053)

This commit is contained in:
Dmytro Naumenko 2020-08-29 00:08:45 +03:00 committed by GitHub
parent 12691991bb
commit 41d5f5567f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 0 deletions

View File

@ -72,6 +72,10 @@ PHP
return null;
}
if ($node->finally !== null && count($node->finally->stmts) > 0) {
return null;
}
$onlyCatchStmt = $onlyCatch->stmts[0];
if (! $onlyCatchStmt instanceof Throw_) {
return null;

View File

@ -0,0 +1,33 @@
<?php
namespace Rector\DeadCode\Tests\Rector\TryCatch\RemoveDeadTryCatchRector\Fixture;
class DropWithEmptyFinally
{
public function run()
{
try {
// some code
} catch (\Throwable $throwable) {
throw $throwable;
} finally {
}
}
}
?>
-----
<?php
namespace Rector\DeadCode\Tests\Rector\TryCatch\RemoveDeadTryCatchRector\Fixture;
class DropWithEmptyFinally
{
public function run()
{
// some code
}
}
?>

View File

@ -0,0 +1,22 @@
<?php
namespace Rector\DeadCode\Tests\Rector\TryCatch\RemoveDeadTryCatchRector\Fixture;
class SkipWithFinally
{
public function run()
{
try {
// some code
} catch (\Throwable $throwable) {
throw $throwable;
} finally {
$this->resetState();
}
}
private function resetState()
{
}
}