Skip to content

Commit 043cea2

Browse files
Remove ignoreDescriptiveUncheckedExceptions (#119)
1 parent 3c4d91c commit 043cea2

10 files changed

+22
-199
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ parameters:
5252
reportUnusedCatchesOfUncheckedExceptions: false
5353
reportUnusedCheckedThrowsInSubtypes: false
5454
reportCheckedThrowsInGlobalScope: false
55-
ignoreDescriptiveUncheckedExceptions: false
5655
checkedExceptions:
5756
- RuntimeException
5857
```

extension.neon

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ parameters:
33
reportUnusedCatchesOfUncheckedExceptions: false
44
reportUnusedCheckedThrowsInSubtypes: false
55
reportCheckedThrowsInGlobalScope: true
6-
ignoreDescriptiveUncheckedExceptions: false
76
checkedExceptions: []
87
uncheckedExceptions: []
98
methodThrowTypeDeclarations: []
@@ -15,7 +14,6 @@ parametersSchema:
1514
reportUnusedCatchesOfUncheckedExceptions: bool()
1615
reportUnusedCheckedThrowsInSubtypes: bool()
1716
reportCheckedThrowsInGlobalScope: bool()
18-
ignoreDescriptiveUncheckedExceptions: bool()
1917
checkedExceptions: listOf(string())
2018
uncheckedExceptions: listOf(string())
2119
methodThrowTypeDeclarations: arrayOf(arrayOf(listOf(string())))
@@ -80,7 +78,6 @@ services:
8078
reportUnusedCatchesOfUncheckedExceptions: %exceptionRules.reportUnusedCatchesOfUncheckedExceptions%
8179
reportUnusedCheckedThrowsInSubtypes: %exceptionRules.reportUnusedCheckedThrowsInSubtypes%
8280
reportCheckedThrowsInGlobalScope: %exceptionRules.reportCheckedThrowsInGlobalScope%
83-
ignoreDescriptiveUncheckedExceptions: %exceptionRules.ignoreDescriptiveUncheckedExceptions%
8481
methodWhitelist: %exceptionRules.methodWhitelist%
8582
tags: [phpstan.rules.rule]
8683

src/Rules/ThrowsPhpDocRule.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ class ThrowsPhpDocRule implements Rule
112112
*/
113113
private $reportCheckedThrowsInGlobalScope;
114114

115-
/**
116-
* @var bool
117-
*/
118-
private $ignoreDescriptiveUncheckedExceptions;
119-
120115
/**
121116
* @var bool
122117
*/
@@ -137,7 +132,6 @@ public function __construct(
137132
bool $reportUnusedCatchesOfUncheckedExceptions,
138133
bool $reportUnusedCheckedThrowsInSubtypes,
139134
bool $reportCheckedThrowsInGlobalScope,
140-
bool $ignoreDescriptiveUncheckedExceptions,
141135
array $methodWhitelist
142136
)
143137
{
@@ -149,7 +143,6 @@ public function __construct(
149143
$this->throwsScope = new ThrowsScope();
150144
$this->reportUnusedCatchesOfUncheckedExceptions = $reportUnusedCatchesOfUncheckedExceptions;
151145
$this->reportCheckedThrowsInGlobalScope = $reportCheckedThrowsInGlobalScope;
152-
$this->ignoreDescriptiveUncheckedExceptions = $ignoreDescriptiveUncheckedExceptions;
153146
$this->reportUnusedCheckedThrowsInSubtypes = $reportUnusedCheckedThrowsInSubtypes;
154147
$this->methodWhitelist = $methodWhitelist;
155148
}
@@ -549,8 +542,7 @@ private function processFunctionEnd(Scope $scope, int $startLine): array
549542
*/
550543
private function filterUnusedExceptions(array $declaredThrows, array $usedThrowsAnnotations, Scope $scope): array
551544
{
552-
$checkedThrowsAnnotations = $this->checkedExceptionService->filterCheckedExceptions($usedThrowsAnnotations);
553-
$unusedThrows = array_diff($declaredThrows, $checkedThrowsAnnotations);
545+
$unusedThrows = array_diff($declaredThrows, $usedThrowsAnnotations);
554546

555547
$functionReflection = $scope->getFunction();
556548
if ($functionReflection === null) {
@@ -581,10 +573,6 @@ private function filterUnusedExceptions(array $declaredThrows, array $usedThrows
581573

582574
$unusedThrows = array_diff($unusedThrows, TypeUtils::getDirectClassNames($defaultThrowsType));
583575

584-
if (!$this->ignoreDescriptiveUncheckedExceptions) {
585-
return $unusedThrows;
586-
}
587-
588576
$throwsAnnotations = $this->throwsAnnotationReader->read($scope);
589577

590578
return array_filter($unusedThrows, static function (string $type) use ($throwsAnnotations, $usedThrowsAnnotations): bool {

tests/src/Rules/Bug113Test.php

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ protected function getRule(): Rule
4848
false,
4949
true,
5050
false,
51-
false,
5251
[]
5352
);
5453
}

tests/src/Rules/PhpInternalsTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ protected function getRule(): Rule
5252
true,
5353
true,
5454
true,
55-
false,
5655
[]
5756
);
5857
}

tests/src/Rules/ThrowsPhpDocRuleTest.php

-13
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ class ThrowsPhpDocRuleTest extends RuleTestCase
3333
*/
3434
private $reportUnusedCheckedThrowsInSubtypes = true;
3535

36-
/**
37-
* @var bool
38-
*/
39-
private $ignoreDescriptiveUncheckedExceptions = false;
40-
4136
/**
4237
* @var bool
4338
*/
@@ -90,7 +85,6 @@ protected function getRule(): Rule
9085
$this->reportUnusedCatchesOfUncheckedExceptions,
9186
$this->reportUnusedCheckedThrowsInSubtypes,
9287
$this->reportCheckedThrowsInGlobalScope,
93-
$this->ignoreDescriptiveUncheckedExceptions,
9488
$this->methodWhitelist
9589
);
9690
}
@@ -134,13 +128,6 @@ public function testAllUnusedCatches(): void
134128
$this->analyse(__DIR__ . '/data/unused-catches-all.php');
135129
}
136130

137-
public function testDescriptiveUnusedCatches(): void
138-
{
139-
$this->reportUnusedCatchesOfUncheckedExceptions = true;
140-
$this->ignoreDescriptiveUncheckedExceptions = true;
141-
$this->analyse(__DIR__ . '/data/unused-descriptive-throws.php');
142-
}
143-
144131
public function testIterators(): void
145132
{
146133
$this->analyse(__DIR__ . '/data/iterators.php');

tests/src/Rules/data/unused-catches-all.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public function correctCatchMethodCallWithThrows(): void
4848
} catch (RuntimeException $e) { // error: RuntimeException is never thrown in the corresponding try block
4949

5050
}
51+
52+
try {
53+
$this->throwLogicWithoutAnnotation();
54+
} catch (LogicException $e) { // error: LogicException is never thrown in the corresponding try block
55+
56+
} catch (RuntimeException $e) { // error: RuntimeException is never thrown in the corresponding try block
57+
58+
}
5159
}
5260

5361
private function someVoidMethod(): void
@@ -57,7 +65,12 @@ private function someVoidMethod(): void
5765
/**
5866
* @throws LogicException
5967
*/
60-
private function throwLogic(): void // error: Unused @throws LogicException annotation
68+
private function throwLogic(): void
69+
{
70+
throw new LogicException();
71+
}
72+
73+
private function throwLogicWithoutAnnotation(): void
6174
{
6275
throw new LogicException();
6376
}

tests/src/Rules/data/unused-catches.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function someVoidMethod(): void
101101
/**
102102
* @throws LogicException
103103
*/
104-
private function throwLogic(): void // error: Unused @throws LogicException annotation
104+
private function throwLogic(): void
105105
{
106106
throw new LogicException();
107107
}

tests/src/Rules/data/unused-descriptive-throws.php

-164
This file was deleted.

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public function unusedBarAnnotation(): void // error: Unused @throws Pepakriz\PH
5454
/**
5555
* @throws LogicException
5656
*/
57-
public function unusedLogic(): void // error: Unused @throws LogicException annotation
57+
public function usedLogic(): void
58+
{
59+
throw new LogicException();
60+
}
61+
62+
public function notMandatoryLogic(): void
5863
{
5964
throw new LogicException();
6065
}

0 commit comments

Comments
 (0)