$ show ekino/phpstan-banned-code
This repository is a PHPStan extension that detects banned code patterns in PHP projects. It provides two main rules: BannedNodesRule to forbid specific function calls and language constructs (like var_dump, exit, echo), and BannedUseTestRule to prevent the use of test namespaces in non-test files. The extension is configured via PHPStan's neon configuration and integrates seamlessly into the PHPStan analysis process. The architecture is straightforward, with each rule implemented as a separate class that processes AST nodes and reports violations. The project demonstrates good practices in PHPStan extension development, including configurable rules, proper error building with non-ignorable options, and thorough unit testing.
The LLM identified 2 files worth highlighting for reuse:
A reusable error builder for PHPStan rules that constructs errors with a configurable prefix and optional non-ignorable flag, promoting consistent error reporting in extensions.
A template rule for banning specific PHP AST node types (including function calls with configurable function names) that demonstrates how to process node configurations and normalize function names for consistent matching.