Warn about misconfiguration
It would be easier to configure PHPStan exception rules correctly if warnings were emitted for potential misconfigurantions. Consider the following configuration file:
parameters:
exceptionRules:
checkedExceptions: # or uncheckedExceptions
- FooException
methodThrowTypeDeclarations:
Bar:
barMethod:
- BarException
functionThrowTypeDeclarations:
bazFunction:
- BazException
includes:
- vendor/pepakriz/phpstan-exception-rules/extension.neon
A warning should be shown when
- FooException does not exist.
- FooException does not implement Throwable.
- Bar does not exist.
- Bar::barMethod does not exist.
- BarException does not exist.
- BarException does not implement Throwable.
- bazFunction does not exist.
- BazException does not exist.
- BazException does not implement Throwable.
Your suggestion leads to make a CompilerExtension https://doc.nette.org/en/2.4/di-extensions which can validate the configuration before DI compilation. But it is not a common solution in phpstan ecosystem. I'd like to know current opinion of @ondrejMirtes, because I've talked with him about this some time ago and he didn't like the idea to depend on concrete DI implementation (Nette DI).
See: https://github.com/phpstan/phpstan/issues/1459
BTW feel free to write your own validation. I just think that CompilerExtension is not especially suitable because you wouldn't have available all the functionality PHPStan can offer (like the Broker instance) during DIC compilation.
I think the best hack how to solve this is to define a service that accepts %exceptionRules% and does just this validation. I'm not sure how to make it instantiated every time though.