-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdead-catch-union.php
55 lines (40 loc) · 1.77 KB
/
dead-catch-union.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php declare(strict_types = 1);
namespace Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion;
use LogicException;
use RuntimeException;
class FooException extends RuntimeException {}
class BarException extends FooException {}
class BazException extends BarException {}
class DeadCatchUnion
{
public function correctUnion(): void
{
try {
} catch (RuntimeException | LogicException $e) {
}
}
public function theSameUnion(): void
{
try {
} catch (FooException | FooException $e) { // error: Type Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\FooException is redundant
}
}
public function deadUnion(): void
{
try {
} catch (FooException | BarException $e) { // error: Type Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\BarException is already caught by Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\FooException
}
}
public function multiDeadUnion(): void
{
try {
} catch (FooException | BarException | BazException $e) { // error: Type Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\BarException is already caught by Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\FooException; Type Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\BazException is already caught by Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\FooException
}
}
public function reverseOrderUnion(): void
{
try {
} catch (BazException | BarException | FooException $e) { // error: Type Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\BazException is already caught by Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\BarException; Type Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\BarException is already caught by Pepakriz\PHPStanExceptionRules\Rules\DeadCatchUnion\FooException
}
}
}