mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-20 06:38:46 +01:00
[TryCatch] Try/Catch with filled Finally can not be dead (#4053)
This commit is contained in:
parent
12691991bb
commit
41d5f5567f
@ -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;
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user