Skip to content

Commit b46e496

Browse files
committed
Validate checkedExceptionClasses config
1 parent e8e58db commit b46e496

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

build/phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ parameters:
3939
- 'PHPStan\ShouldNotHappenException'
4040
- 'Symfony\Component\Console\Exception\InvalidArgumentException'
4141
- 'PHPStan\BetterReflection\SourceLocator\Exception\InvalidFileLocation'
42-
- 'PHPStan\BetterReflection\SourceLocator\Exception\InvalidArgumentException'
4342
- 'Symfony\Component\Finder\Exception\DirectoryNotFoundException'
4443
- 'InvalidArgumentException'
4544
- 'PHPStan\DependencyInjection\ParameterNotFoundException'

src/Rules/Exceptions/DefaultExceptionTypeResolver.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Nette\Utils\Strings;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\ReflectionProvider;
8+
use PHPStan\ShouldNotHappenException;
89
use function count;
910

1011
/**
@@ -27,6 +28,16 @@ public function __construct(
2728
private array $checkedExceptionClasses,
2829
)
2930
{
31+
foreach ($this->checkedExceptionClasses as $checkedExceptionClass) {
32+
if (!$this->reflectionProvider->hasClass($checkedExceptionClass)) {
33+
throw new ShouldNotHappenException('Class ' . $checkedExceptionClass . ' used in \'checkedExceptionClasses\' does not exist.');
34+
}
35+
}
36+
foreach ($this->uncheckedExceptionClasses as $uncheckedExceptionClass) {
37+
if (!$this->reflectionProvider->hasClass($uncheckedExceptionClass)) {
38+
throw new ShouldNotHappenException('Class ' . $uncheckedExceptionClass . ' used in \'uncheckedExceptionClasses\' does not exist.');
39+
}
40+
}
3041
}
3142

3243
public function isCheckedException(string $className, Scope $scope): bool

0 commit comments

Comments
 (0)