pepakriz/phpstan-exception-rules
PHPStan extension that adds custom rules for analyzing exceptions. It helps catch improper throwing/catching, missing @throws annotations, and other exception-related issues to improve correctness and maintainability in PHP codebases.
composer require --dev pepakriz/phpstan-exception-rulesphpstan.neon:
includes:
- vendor/pepakriz/phpstan-exception-rules/rules.neon
@throws — especially public methods, service constructors, and API endpoints where exception contracts matter most.allowMissingThrows: false for these namespaces.rector/rector to auto-add @throws for methods where exceptions are guaranteed (e.g., all try { return $client->request(); } catch (\Exception $e) { throw $e; }).@throws and inferred exceptions — it won’t detect runtime-only exceptions (e.g., throw new \Error). Complement with runtime test coverage.@throws, running this may produce noisy false positives — generate a baseline (phpstan generate-baseline) and treat @throws as “living documentation” updated incrementally.@throws are inconsistent — verify via --debug or use parameters.leverageInheritance: true (if supported by version).ExceptionTagMethodReflectionExtension — custom method wrappers or dynamic callable proxies may need explicit @throws even if inferred trivially.How can I help you explore Laravel packages today?