This project uses PHPStan for static analysis and PHP-CS-Fixer for code style enforcement.
PHPStan analyzes code for potential bugs, type errors, and code quality issues without running the code.
- Level: 5 (moderate strictness)
- Config file:
phpstan.neon - Paths analyzed:
src/
# Run analysis
composer analyse
# Or directly
docker exec vibereader php vendor/bin/phpstan analyse --configuration=phpstan.neon
# Generate baseline (ignore current errors)
composer analyse-baselinePHPStan is configured at level 5 and analyzes all source files. Some known limitations:
- Monolog classes are ignored (they exist but PHPStan can't always detect them)
- RedisCache is excluded (may not have Redis extension in all environments)
PHP-CS-Fixer automatically fixes code style to match PSR-12 standards.
- Standard: PSR-12
- Config file:
.php-cs-fixer.php - Rules: Array syntax, ordered imports, trailing commas, etc.
# Check what would be changed (dry-run)
composer cs-check
# Fix code style issues
composer cs-fix
# Or directly
docker exec vibereader php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php src/- PSR-12 compliance
- Array syntax (
[]instead ofarray()) - Ordered imports (alphabetically)
- Removes unused imports
- Trailing commas in multiline arrays
- Spacing around operators
- Consistent formatting
-
Run PHP-CS-Fixer to ensure consistent style:
composer cs-fix
-
Run PHPStan to catch potential issues:
composer analyse
-
Run tests:
composer test
These tools can be integrated into CI/CD pipelines:
# Example GitHub Actions
- name: Check code style
run: composer cs-check
- name: Run static analysis
run: composer analyse
- name: Run tests
run: composer testSince the project runs in Docker, use these commands:
# PHPStan
docker exec vibereader php vendor/bin/phpstan analyse --configuration=phpstan.neon
# PHP-CS-Fixer
docker exec vibereader php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php src/If PHPStan reports classes as "not found" but they exist:
- Check that
vendor/autoload.phpis inbootstrapFiles - Verify the class is in the autoloaded namespace
- Add to
ignoreErrorsif it's a false positive
If PHP-CS-Fixer makes unwanted changes:
- Review
.php-cs-fixer.phpconfiguration - Adjust rules in the
setRules()array - Run with
--dry-runfirst to preview changes
If PHPStan runs out of memory:
php vendor/bin/phpstan analyse --memory-limit=1G- Early Bug Detection: PHPStan finds issues before runtime
- Consistent Style: PHP-CS-Fixer ensures uniform code formatting
- Better IDE Support: Static analysis improves autocomplete and error detection
- Code Review: Automated checks reduce manual review burden
- Maintainability: Consistent style makes code easier to read and maintain