Skip to content

Commit

Permalink
[CodingStyle] Skip jump change variable name on CatchExceptionNameMat…
Browse files Browse the repository at this point in the history
…chingTypeRector (#3931)

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
samsonasik and actions-user authored May 22, 2023
1 parent 88f17e9 commit 4793a0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture;

class SkipChangevariableNextJumpTry
{
public function run()
{
if (rand(0, 1)) {
try {
} catch (SomeException $typoException) {
}
}

if (isset($typoException)) {
$this->verify($typoException);
$this->verify2($typoException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Catch_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\TryCatch;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ObjectType;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\Naming\AliasNameResolver;
use Rector\Naming\Naming\PropertyNaming;
Expand Down Expand Up @@ -81,11 +85,17 @@ public function run()
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [
ClassMethod::class,
Function_::class,
Closure::class,
FileWithoutNamespace::class,
Namespace_::class,
];
}

/**
* @param StmtsAwareInterface $node
* @param ClassMethod|Function_|Closure|FileWithoutNamespace|Namespace_ $node
*/
public function refactor(Node $node): ?Node
{
Expand Down

0 comments on commit 4793a0d

Please sign in to comment.