[CodingStyle] Handle more than one method contains try catch on CatchExceptionNameMatchingTypeRector (#1706)

* Add failing test fixture for CatchExceptionNameMatchingTypeRector

# Failing Test for CatchExceptionNameMatchingTypeRector

Based on https://getrector.org/demo/1ec7a611-571e-6c18-8335-c5ffee726af7

* Closes #1705

Co-authored-by: Zing <zingimmick@outlook.com>
This commit is contained in:
Abdul Malik Ikhsan 2022-01-21 13:06:34 +07:00 committed by GitHub
parent 672b339ebd
commit 2934929fac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 1 deletions

View File

@ -0,0 +1,49 @@
<?php
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture;
use Throwable;
final class MoreThanOneMethodContainsTryCatch
{
public function run()
{
try {
} catch (Throwable $exception) {
}
}
public function more()
{
try {
} catch (Throwable $exception) {
}
}
}
?>
-----
<?php
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture;
use Throwable;
final class MoreThanOneMethodContainsTryCatch
{
public function run()
{
try {
} catch (Throwable $throwable) {
}
}
public function more()
{
try {
} catch (Throwable $throwable) {
}
}
}
?>

View File

@ -0,0 +1,41 @@
<?php
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture;
use Throwable;
final class MoreThanOneTryCatch
{
public function run()
{
try {
} catch (Throwable $exception) {
}
try {
} catch (Throwable $exception) {
}
}
}
?>
-----
<?php
namespace Rector\Tests\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector\Fixture;
use Throwable;
final class MoreThanOneTryCatch
{
public function run()
{
try {
} catch (Throwable $throwable) {
}
try {
} catch (Throwable $throwable) {
}
}
}
?>

View File

@ -113,7 +113,7 @@ CODE_SAMPLE
}
$newVariable = new Variable($newVariableName);
$isFoundInPrevious = (bool) $this->betterNodeFinder->findFirstPrevious(
$isFoundInPrevious = (bool) $this->betterNodeFinder->findFirstPreviousOfNode(
$node,
fn (Node $n): bool => $this->nodeComparator->areNodesEqual($n, $newVariable)
);