mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-06 19:30:50 +00:00
[DeadCode] Add Closure support on RemoveLastReturnRector (#1993)
This commit is contained in:
parent
759b7c881d
commit
7a37df2b60
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
class InClassMethod
|
||||
{
|
||||
function run($value) {
|
||||
if ($value === 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
class InClassMethod
|
||||
{
|
||||
function run($value) {
|
||||
if ($value === 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
function ($value) {
|
||||
if ($value === 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
function ($value) {
|
||||
if ($value === 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
function some_function($value)
|
||||
function InFunction($value)
|
||||
{
|
||||
if ($value === 1000) {
|
||||
return;
|
||||
|
@ -19,7 +19,7 @@ function some_function($value)
|
|||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
function some_function($value)
|
||||
function InFunction($value)
|
||||
{
|
||||
if ($value === 1000) {
|
||||
return;
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
class InInnerClosure
|
||||
{
|
||||
function run($value) {
|
||||
$value = (bool) function ($value) {
|
||||
if ($value === 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveLastReturnRector\Fixture;
|
||||
|
||||
class InInnerClosure
|
||||
{
|
||||
function run($value) {
|
||||
$value = (bool) function ($value) {
|
||||
if ($value === 1000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
}
|
||||
};
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Rector\DeadCode\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
|
@ -61,7 +62,7 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class, Function_::class];
|
||||
return [ClassMethod::class, Function_::class, Closure::class];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,10 +78,6 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
if (! $lastNode instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($lastNode !== $lastReturn) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user