This project uses PHPStan for static code analysis at level 8 (the strictest level).
Run static analysis:
composer stanOr use PHPStan directly:
vendor/bin/phpstan analysePHPStan is configured via phpstan.neon with the following settings:
- Analysis Level: 8 (strictest)
- Analyzed Paths:
src/directory - Excluded Paths:
tests/directory - Bootstrap Files: CakePHP Core and I18n functions for proper analysis
The configuration ignores some errors that are expected in CakePHP applications:
- I18n Functions - CakePHP translation functions like
__d()are loaded via bootstrap files
These are standard patterns in CakePHP and don't represent actual errors.
If you need to add PHPStan to an existing project with many errors, you can generate a baseline:
vendor/bin/phpstan analyse --generate-baselineThis creates phpstan-baseline.neon which allows you to gradually fix issues without blocking CI.
Add PHPStan to your continuous integration:
# GitHub Actions example
- name: PHPStan Analysis
run: composer stan# GitLab CI example
phpstan:
script:
- composer install
- composer stan- Go to Settings → PHP → Quality Tools → PHPStan
- Point to
vendor/bin/phpstan - Enable automatic inspection
Install the PHPStan extension:
code --install-extension calsmurf2904.vscode-phpstanPHPStan has 10 levels (0-9). This project uses level 8:
- Level 0: Basic checks
- Level 4: Dead code detection
- Level 6: Type inference
- Level 8: Strict type checking (used here)
- Level 9: Mixed type checks (very strict)
If PHPStan runs out of memory:
# Increase memory limit
composer stan -- --memory-limit=1GIf you encounter false positives, you can add them to ignoreErrors in phpstan.neon:
parameters:
ignoreErrors:
- '#Your error pattern here#'To exclude specific files or directories:
parameters:
excludePaths:
- src/Legacy/*
- src/Generated/*Running PHPStan helps catch:
- Type errors before runtime
- Undefined methods and properties
- Dead code
- Incorrect PHPDoc types
- Logic errors
- Parameter type mismatches