| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Rules\Exceptions; |
| 4: | |
| 5: | use PHPStan\Analyser\Scope; |
| 6: | |
| 7: | /** |
| 8: | * @api |
| 9: | * |
| 10: | * This interface allows you to write custom logic that can dynamically decide |
| 11: | * whether an exception is checked or unchecked type. |
| 12: | * |
| 13: | * Because the interface accepts a Scope, you can ask about the place in the code where |
| 14: | * it's being decided - a file, a namespace or a class name. |
| 15: | * |
| 16: | * There can only be a single ExceptionTypeResolver per project, and you can register it |
| 17: | * in your configuration file like this: |
| 18: | * |
| 19: | * ``` |
| 20: | * services: |
| 21: | * exceptionTypeResolver!: |
| 22: | * class: PHPStan\Rules\Exceptions\ExceptionTypeResolver |
| 23: | * ``` |
| 24: | * |
| 25: | * You can also take advantage of the `PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver` |
| 26: | * by injecting it into the constructor of your ExceptionTypeResolver |
| 27: | * and delegate the logic of the classes and places you don't care about. |
| 28: | * |
| 29: | * DefaultExceptionTypeResolver decides the type of the exception based on configuration |
| 30: | * parameters like `exceptions.uncheckedExceptionClasses` etc. |
| 31: | * |
| 32: | * Learn more: https://phpstan.org/blog/bring-your-exceptions-under-control |
| 33: | */ |
| 34: | interface ExceptionTypeResolver |
| 35: | { |
| 36: | |
| 37: | public function isCheckedException(string $className, Scope $scope): bool; |
| 38: | |
| 39: | } |
| 40: |