Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodingStyle] Skip jump change variable name on CatchExceptionNameMatchingTypeRector #3931

Merged
merged 5 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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