pepakriz / phpstan-exception-rules

PHPStan rules for checked & unchecked exceptions
107 stars 9 forks source link

Warn about misconfiguration #29

Open Stadly opened 6 years ago

Stadly commented 6 years ago

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

pepakriz commented 6 years ago

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).

ondrejmirtes commented 6 years ago

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.

ondrejmirtes commented 5 years ago

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.