Skip to content

PHPStan AST Rules Extension

The themattosdev/leakless-dev package provides a dedicated PHPStan extension (extension.neon) containing AST rules to inspect your code during static analysis.


Configuration

Include the extension in your project's phpstan.neon:

yaml
includes:
    - vendor/themattosdev/leakless-dev/extension.neon

parameters:
    level: max
    paths:
        - app
        - src
    ignoreErrors:
        - '#Call to an undefined method Pest\\Expectation.*::(toBeLeakless|toRunCleanly)\(\)#'

Included AST Rules

Rule ClassWhat It Enforces
BanMutableStaticPropertiesRuleDisallows mutable static properties on classes unless marked with #[AllowPersistentState].
BanEphemeralInjectionInSingletonsRulePrevents constructor injection of Request / Session in singleton services.
BanSuperglobalsAndTerminatorsRuleBlocks direct $_GET, $_POST, $_SESSION, exit(), die(), and session_start().
BanIncompatibleWorkerFunctionsRuleDetects get_browser(), GLOB_BRACE on Alpine musl, ext-imap, and direct procedural headers.

Released under the MIT License.