-
Notifications
You must be signed in to change notification settings - Fork 516
Validate checkedExceptionClasses config #3987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.1.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use Nette\Utils\Strings; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\ReflectionProvider; | ||
use PHPStan\ShouldNotHappenException; | ||
use function count; | ||
|
||
/** | ||
|
@@ -27,6 +28,16 @@ public function __construct( | |
private array $checkedExceptionClasses, | ||
) | ||
{ | ||
foreach ($this->checkedExceptionClasses as $checkedExceptionClass) { | ||
if (!$this->reflectionProvider->hasClass($checkedExceptionClass)) { | ||
throw new ShouldNotHappenException('Class ' . $checkedExceptionClass . ' used in \'checkedExceptionClasses\' does not exist.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a BC break. Also I'd prefer it if happened in ContainerFactory. There's already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So yeah, please put this only in bleeding edge. |
||
} | ||
} | ||
foreach ($this->uncheckedExceptionClasses as $uncheckedExceptionClass) { | ||
if (!$this->reflectionProvider->hasClass($uncheckedExceptionClass)) { | ||
throw new ShouldNotHappenException('Class ' . $uncheckedExceptionClass . ' used in \'uncheckedExceptionClasses\' does not exist.'); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want that behind featureFlag / bleedingEdge? I think this will be pretty rare. |
||
} | ||
|
||
public function isCheckedException(string $className, Scope $scope): bool | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the preferred way of config validation.