Skip to content

Commit b11218b

Browse files
committed
Revert Too wide throws type - skip Throwable
1 parent 181f75c commit b11218b

6 files changed

Lines changed: 32 additions & 26 deletions

File tree

src/Reflection/BetterReflection/Reflector/MemoizingClassReflector.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\BetterReflection\Reflection\Reflection;
66
use PHPStan\BetterReflection\Reflector\ClassReflector;
7-
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
87

98
final class MemoizingClassReflector extends ClassReflector
109
{
@@ -17,7 +16,7 @@ final class MemoizingClassReflector extends ClassReflector
1716
*
1817
* @return \PHPStan\BetterReflection\Reflection\ReflectionClass
1918
*
20-
* @throws IdentifierNotFound
19+
* @throws \PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound
2120
*/
2221
public function reflect(string $className): Reflection
2322
{
@@ -31,9 +30,6 @@ public function reflect(string $className): Reflection
3130

3231
try {
3332
return $this->reflections[$lowerClassName] = parent::reflect($className);
34-
} catch (IdentifierNotFound $e) {
35-
$this->reflections[$lowerClassName] = $e;
36-
throw $e;
3733
} catch (\Throwable $e) {
3834
$this->reflections[$lowerClassName] = $e;
3935
throw $e;

src/Reflection/BetterReflection/Reflector/MemoizingConstantReflector.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\BetterReflection\Reflection\Reflection;
66
use PHPStan\BetterReflection\Reflector\ConstantReflector;
7-
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
87

98
final class MemoizingConstantReflector extends ConstantReflector
109
{
@@ -17,7 +16,7 @@ final class MemoizingConstantReflector extends ConstantReflector
1716
*
1817
* @return \PHPStan\BetterReflection\Reflection\ReflectionConstant
1918
*
20-
* @throws IdentifierNotFound
19+
* @throws \PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound
2120
*/
2221
public function reflect(string $constantName): Reflection
2322
{
@@ -30,9 +29,6 @@ public function reflect(string $constantName): Reflection
3029

3130
try {
3231
return $this->reflections[$constantName] = parent::reflect($constantName);
33-
} catch (IdentifierNotFound $e) {
34-
$this->reflections[$constantName] = $e;
35-
throw $e;
3632
} catch (\Throwable $e) {
3733
$this->reflections[$constantName] = $e;
3834
throw $e;

src/Reflection/BetterReflection/Reflector/MemoizingFunctionReflector.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Reflection\BetterReflection\Reflector;
44

55
use PHPStan\BetterReflection\Reflection\Reflection;
6-
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
76
use PHPStan\BetterReflection\Reflector\FunctionReflector;
87

98
final class MemoizingFunctionReflector extends FunctionReflector
@@ -17,7 +16,7 @@ final class MemoizingFunctionReflector extends FunctionReflector
1716
*
1817
* @return \PHPStan\BetterReflection\Reflection\ReflectionFunction
1918
*
20-
* @throws IdentifierNotFound
19+
* @throws \PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound
2120
*/
2221
public function reflect(string $functionName): Reflection
2322
{
@@ -31,9 +30,6 @@ public function reflect(string $functionName): Reflection
3130

3231
try {
3332
return $this->reflections[$lowerFunctionName] = parent::reflect($functionName);
34-
} catch (IdentifierNotFound $e) {
35-
$this->reflections[$lowerFunctionName] = $e;
36-
throw $e;
3733
} catch (\Throwable $e) {
3834
$this->reflections[$lowerFunctionName] = $e;
3935
throw $e;

src/Rules/Exceptions/TooWideThrowTypeCheck.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Analyser\ThrowPoint;
66
use PHPStan\Type\NeverType;
7-
use PHPStan\Type\ObjectType;
87
use PHPStan\Type\Type;
98
use PHPStan\Type\TypeCombinator;
109
use PHPStan\Type\TypeUtils;
@@ -30,12 +29,7 @@ public function check(Type $throwType, array $throwPoints): array
3029
return new NeverType();
3130
}
3231

33-
$type = $throwPoint->getType();
34-
if ($type->isSuperTypeOf(new ObjectType(\Throwable::class))->yes()) {
35-
return new NeverType();
36-
}
37-
38-
return $type;
32+
return $throwPoint->getType();
3933
}, $throwPoints));
4034

4135
$throwClasses = [];

tests/PHPStan/Rules/Exceptions/TooWideMethodThrowTypeRuleTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public function testRule(): void
4040
'Method TooWideThrowsMethod\ParentClass::doFoo() has LogicException in PHPDoc @throws tag but it\'s not thrown.',
4141
77,
4242
],
43-
[
44-
'Method TooWideThrowsMethod\SkipThrowable::doFoo() has DomainException in PHPDoc @throws tag but it\'s not thrown.',
45-
112,
46-
],
4743
]);
4844
}
4945

tests/PHPStan/Rules/Exceptions/data/too-wide-throws-method.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,32 @@ public function doFoo(\Throwable $t)
118118
throw $t;
119119
}
120120

121+
/**
122+
* @throws \InvalidArgumentException
123+
*/
124+
public function doBar(): void
125+
{
126+
try {
127+
throw new \InvalidArgumentException();
128+
} catch (\Throwable $e) {
129+
throw $e;
130+
}
131+
}
132+
133+
/**
134+
* @throws \InvalidArgumentException
135+
*/
136+
public function doBaz(): void
137+
{
138+
try {
139+
if (rand(0, 1)) {
140+
throw new \InvalidArgumentException();
141+
}
142+
143+
doFoo();
144+
} catch (\Throwable $e) {
145+
throw $e;
146+
}
147+
}
148+
121149
}

0 commit comments

Comments
 (0)