mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-11 05:32:23 +00:00
[Php56] Skip multiple catch with same variable on AddDefaultValueForUndefinedVariableRector (#2533)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
87b3dad341
commit
4eeadae7bf
|
@ -11,6 +11,7 @@ use PhpParser\Node\Expr\Assign;
|
|||
use PhpParser\Node\Expr\AssignOp;
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
@ -41,6 +42,7 @@ use Rector\Core\Exception\ShouldNotHappenException;
|
|||
use Rector\Core\StaticReflection\SourceLocator\ParentAttributeSourceLocator;
|
||||
use Rector\Core\StaticReflection\SourceLocator\RenamedClassesSourceLocator;
|
||||
use Rector\Core\Util\StringUtils;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\RemoveDeepChainMethodCallNodeVisitor;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||
|
@ -74,6 +76,7 @@ final class PHPStanNodeScopeResolver
|
|||
private readonly PrivatesAccessor $privatesAccessor,
|
||||
private readonly RenamedClassesSourceLocator $renamedClassesSourceLocator,
|
||||
private readonly ParentAttributeSourceLocator $parentAttributeSourceLocator,
|
||||
private readonly NodeNameResolver $nodeNameResolver
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -138,7 +141,11 @@ final class PHPStanNodeScopeResolver
|
|||
|
||||
if ($node instanceof TryCatch) {
|
||||
foreach ($node->catches as $catch) {
|
||||
$this->processNodes($catch->stmts, $smartFileInfo, $mutatingScope);
|
||||
$varName = $catch->var instanceof Variable
|
||||
? $this->nodeNameResolver->getName($catch->var)
|
||||
: null;
|
||||
$catchMutatingScope = $mutatingScope->enterCatch($catch->types, $varName);
|
||||
$this->processNodes($catch->stmts, $smartFileInfo, $catchMutatingScope);
|
||||
}
|
||||
|
||||
if ($node->finally instanceof Finally_) {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector\Fixture;
|
||||
|
||||
class SkipCatchUseVariable
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
} catch (\Exception $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
}
|
||||
|
||||
public function run2()
|
||||
{
|
||||
try {
|
||||
} catch (\Exception $e) {
|
||||
$e;
|
||||
}
|
||||
}
|
||||
|
||||
public function run3()
|
||||
{
|
||||
try {
|
||||
} catch (\Exception $e) {
|
||||
echo $e::class;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector\Fixture;
|
||||
|
||||
class SkipMultipleCatchWithUseSameVariable
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
} catch (\Exception $e) {
|
||||
var_dump($e);
|
||||
} catch (\Throwable $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
}
|
||||
|
||||
public function run2()
|
||||
{
|
||||
try {
|
||||
} catch (\Exception $e) {
|
||||
$e;
|
||||
} catch (\Throwable $e) {
|
||||
$e;
|
||||
}
|
||||
}
|
||||
|
||||
public function run3()
|
||||
{
|
||||
try {
|
||||
} catch (\Exception $e) {
|
||||
echo $e::class;
|
||||
} catch (\Throwable $e) {
|
||||
echo $e::class;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user