Skip to content

Commit 461c803

Browse files
committed
Removed support for ignoredExceptions - problematic feature when inheritance is used
1 parent f5e1929 commit 461c803

File tree

7 files changed

+7
-51
lines changed

7 files changed

+7
-51
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ parameters:
4141
exceptionRules:
4242
checkedExceptions:
4343
- RuntimeException
44-
ignoredExceptions:
45-
- LogicException
4644
```
4745

4846
## Motivation

extension.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ parameters:
22
exceptionRules:
33
reportMaybes: true
44
checkedExceptions: []
5-
ignoredExceptions: []
65

76
services:
87
-
9-
class: Pepakriz\PHPStanExceptionRules\CheckedExceptionService(%exceptionRules.checkedExceptions%, %exceptionRules.ignoredExceptions%)
8+
class: Pepakriz\PHPStanExceptionRules\CheckedExceptionService(%exceptionRules.checkedExceptions%)
109

1110
-
1211
class: Pepakriz\PHPStanExceptionRules\Rules\ThrowsPhpDocRule

phpstan.neon.dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,4 @@ parameters:
1212
- %rootDir%/../../../tests/*/data/*
1313

1414
exceptionRules:
15-
checkedExceptions:
16-
- RuntimeException
17-
ignoredExceptions:
18-
- LogicException
19-
- PHPUnit\Framework\Exception
20-
- Nette\DI\MissingServiceException
15+
checkedExceptions: []

src/CheckedExceptionService.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,22 @@ class CheckedExceptionService
1010
/**
1111
* @var string[]
1212
*/
13-
private $exceptionWhiteList;
13+
private $checkedExceptions;
1414

1515
/**
16-
* @var string[]
17-
*/
18-
private $exceptionBlackList;
19-
20-
/**
21-
* @param string[] $exceptionWhiteList
22-
* @param string[] $exceptionBlackList
16+
* @param string[] $checkedExceptions
2317
*/
2418
public function __construct(
25-
array $exceptionWhiteList,
26-
array $exceptionBlackList
19+
array $checkedExceptions
2720
)
2821
{
29-
$this->exceptionWhiteList = $exceptionWhiteList;
30-
$this->exceptionBlackList = $exceptionBlackList;
22+
$this->checkedExceptions = $checkedExceptions;
3123
}
3224

3325
public function isExceptionClassWhitelisted(string $exceptionClassName): bool
3426
{
35-
foreach ($this->exceptionWhiteList as $whitelistedException) {
27+
foreach ($this->checkedExceptions as $whitelistedException) {
3628
if (is_a($exceptionClassName, $whitelistedException, true)) {
37-
foreach ($this->exceptionBlackList as $blacklistedException) {
38-
if (!is_a($exceptionClassName, $blacklistedException, true)) {
39-
continue;
40-
}
41-
42-
if (is_a($blacklistedException, $whitelistedException, true)) {
43-
continue 2;
44-
}
45-
}
46-
4729
return true;
4830
}
4931
}

tests/src/Rules/ThrowsPhpDocInheritanceRuleTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Pepakriz\PHPStanExceptionRules\Rules;
44

5-
use LogicException;
65
use Pepakriz\PHPStanExceptionRules\CheckedExceptionService;
76
use Pepakriz\PHPStanExceptionRules\RuleTestCase;
87
use PHPStan\Rules\Rule;
@@ -18,9 +17,6 @@ protected function getRule(): Rule
1817
new CheckedExceptionService(
1918
[
2019
RuntimeException::class,
21-
],
22-
[
23-
LogicException::class,
2420
]
2521
),
2622
self::getContainer()->getByType(FileTypeMapper::class),

tests/src/Rules/ThrowsPhpDocRuleTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace Pepakriz\PHPStanExceptionRules\Rules;
44

55
use Pepakriz\PHPStanExceptionRules\CheckedExceptionService;
6-
use Pepakriz\PHPStanExceptionRules\Rules\Data\BaseBlacklistedRuntimeException;
76
use Pepakriz\PHPStanExceptionRules\Rules\Data\CheckedException;
8-
use Pepakriz\PHPStanExceptionRules\Rules\Data\SomeBlacklistedRuntimeException;
97
use Pepakriz\PHPStanExceptionRules\RuleTestCase;
108
use PHPStan\Rules\Rule;
119
use RuntimeException;
@@ -20,10 +18,6 @@ protected function getRule(): Rule
2018
[
2119
RuntimeException::class,
2220
CheckedException::class,
23-
],
24-
[
25-
BaseBlacklistedRuntimeException::class,
26-
SomeBlacklistedRuntimeException::class,
2721
]
2822
),
2923
$this->createBroker()

tests/src/Rules/data/throws-annotations.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ abstract class BaseBlacklistedRuntimeException extends BaseRuntimeException {}
1212
class SomeRuntimeException extends BaseRuntimeException {}
1313
class NextRuntimeException extends BaseRuntimeException {}
1414
class ConcreteNextRuntimeException extends NextRuntimeException {}
15-
class SomeBlacklistedRuntimeException extends BaseRuntimeException {}
16-
class SomeInheritedBlacklistedRuntimeException extends BaseBlacklistedRuntimeException {}
1715
class CheckedException extends Exception {}
1816

1917
class ThrowsAnnotationsClass
@@ -32,12 +30,6 @@ public function ignoreNonWhitelisted(): void
3230
throw new CustomLogicException();
3331
}
3432

35-
public function ignoreBlacklisted(): void
36-
{
37-
throw new SomeBlacklistedRuntimeException();
38-
throw new SomeInheritedBlacklistedRuntimeException();
39-
}
40-
4133
/**
4234
* @throws SomeRuntimeException
4335
*/

0 commit comments

Comments
 (0)