Skip to content

Commit 3cfbc85

Browse files
committed
[CodeQuality] Skip no code parameter on custom Throwable instance on ThrowWithPreviousExceptionRector
1 parent e4081fe commit 3cfbc85

8 files changed

Lines changed: 43 additions & 16 deletions

rules-tests/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector/Fixture/empty_brackets.php.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class EmptyBrackets
88
{
99
try {
1010
$someCode = 1;
11-
} catch (Throwable $throwable) {
12-
throw new AnotherException;
11+
} catch (\Throwable $throwable) {
12+
throw new \RuntimeException;
1313
}
1414
}
1515
}
@@ -26,8 +26,8 @@ class EmptyBrackets
2626
{
2727
try {
2828
$someCode = 1;
29-
} catch (Throwable $throwable) {
30-
throw new AnotherException($throwable->getMessage(), $throwable->getCode(), $throwable);
29+
} catch (\Throwable $throwable) {
30+
throw new \RuntimeException($throwable->getMessage(), $throwable->getCode(), $throwable);
3131
}
3232
}
3333
}

rules-tests/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector/Fixture/fixture.php.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class Fixture
88
{
99
try {
1010
$someCode = 1;
11-
} catch (Throwable $throwable) {
12-
throw new AnotherException('ups');
11+
} catch (\Throwable $throwable) {
12+
throw new \RuntimeException('ups');
1313
}
1414
}
1515
}
@@ -26,8 +26,8 @@ class Fixture
2626
{
2727
try {
2828
$someCode = 1;
29-
} catch (Throwable $throwable) {
30-
throw new AnotherException('ups', $throwable->getCode(), $throwable);
29+
} catch (\Throwable $throwable) {
30+
throw new \RuntimeException('ups', $throwable->getCode(), $throwable);
3131
}
3232
}
3333
}

rules-tests/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector/Fixture/named_argument.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class NamedArgument
99
try {
1010
$this->run();
1111
}catch(\Throwable $throwable) {
12-
throw new LogicException('Some exception', previous: $throwable);
12+
throw new \LogicException('Some exception', previous: $throwable);
1313
}
1414
}
1515
}
@@ -27,7 +27,7 @@ class NamedArgument
2727
try {
2828
$this->run();
2929
}catch(\Throwable $throwable) {
30-
throw new LogicException('Some exception', $throwable->getCode(), previous: $throwable);
30+
throw new \LogicException('Some exception', $throwable->getCode(), previous: $throwable);
3131
}
3232
}
3333
}

rules-tests/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector/Fixture/named_argument_for_message.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class NamedArgumentForMessage
99
try {
1010
$this->run();
1111
}catch(\Throwable $throwable) {
12-
throw new LogicException(message: 'Some exception');
12+
throw new \LogicException(message: 'Some exception');
1313
}
1414
}
1515
}
@@ -27,7 +27,7 @@ class NamedArgumentForMessage
2727
try {
2828
$this->run();
2929
}catch(\Throwable $throwable) {
30-
throw new LogicException(message: 'Some exception', code: $throwable->getCode(), previous: $throwable);
30+
throw new \LogicException(message: 'Some exception', code: $throwable->getCode(), previous: $throwable);
3131
}
3232
}
3333
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Catch_\ThrowWithPreviousExceptionRector\Fixture;
4+
5+
use stdClass;
6+
7+
class Error extends \Exception
8+
{
9+
public function __construct(
10+
string $message = '',
11+
$nodes = null,
12+
?stdClass $source = null,
13+
?array $positions = null,
14+
?array $path = null,
15+
?\Throwable $previous = null,
16+
?array $extensions = null,
17+
?array $unaliasedPath = null
18+
) {
19+
parent::__construct($message, 0, $previous);
20+
}
21+
}
22+
23+
try {
24+
throw new \InvalidArgumentException('foo');
25+
} catch (\InvalidArgumentException $e) {
26+
throw new Error(message: 'Some error message', previous: $e);
27+
}

rules-tests/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector/Fixture/skip_custom_exception_param_order_flipped_no_namespace.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HttpException extends \RuntimeException
1919

2020
class BadGatewayHttpException extends HttpException
2121
{
22-
public function __construct(string $message = '', ?Throwable $previous = null, array $headers = [], int $code = 0)
22+
public function __construct(string $message = '', ?\Throwable $previous = null, array $headers = [], int $code = 0)
2323
{
2424
parent::__construct(Response::HTTP_BAD_GATEWAY, $message, $previous, $headers, $code);
2525
}

rules-tests/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector/Fixture/skip_filled_exception_with_different_location.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class SkipFilledExceptionWithDifferentLocation
1010
public function run()
1111
{
1212
try {
13-
} catch (Throwable $throwable) {
13+
} catch (\Throwable $throwable) {
1414
throw new BadRequestHttpException('message some', $throwable);
1515
}
1616
}
1717
}
1818

1919
class BadRequestHttpException extends Exception
2020
{
21-
public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = [])
21+
public function __construct(string $message = null, ?\Throwable $previous = null, int $code = 0, array $headers = [])
2222
{
2323
parent::__construct('message', 400, $previous);
2424
}

rules-tests/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector/Fixture/skip_missing_location.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SkipMissingLocation
1010
public function run()
1111
{
1212
try {
13-
} catch (Throwable $throwable) {
13+
} catch (\Throwable $throwable) {
1414
throw new MissingPreviousException('message some');
1515
}
1616
}

0 commit comments

Comments
 (0)