|
| 1 | +# Code Quality |
| 2 | + |
| 3 | +This project uses PHPStan for static analysis and Rector for automated code refactoring to maintain high code quality standards. |
| 4 | + |
| 5 | +## PHPStan - Static Analysis |
| 6 | + |
| 7 | +PHPStan analyzes the code for potential issues and type safety problems. The configuration is stored in `phpstan.neon.dist`. |
| 8 | + |
| 9 | +### Generate a new baseline |
| 10 | +When introducing PHPStan to legacy code or after major refactoring, you can create a baseline to suppress existing errors: |
| 11 | +```bash |
| 12 | +vendor/bin/phpstan analyse --generate-baseline |
| 13 | +``` |
| 14 | + |
| 15 | +### Run analysis |
| 16 | +To analyze the codebase and find issues: |
| 17 | +```bash |
| 18 | +vendor/bin/phpstan analyse |
| 19 | +``` |
| 20 | + |
| 21 | +### Configuration |
| 22 | +- Configuration file: `phpstan.neon.dist` |
| 23 | +- Current analysis level: 5 |
| 24 | +- Baseline file: `phpstan-baseline.neon` (suppresses known issues) |
| 25 | + |
| 26 | +## Rector - Automated Refactoring |
| 27 | + |
| 28 | +Rector automatically modernizes PHP code and applies coding standards. The configuration is stored in `rector.php`. |
| 29 | + |
| 30 | +### Preview changes (recommended first step) |
| 31 | +Run a dry-run to see what changes Rector would make without actually modifying files: |
| 32 | +```bash |
| 33 | +vendor/bin/rector process --dry-run |
| 34 | +``` |
| 35 | + |
| 36 | +### Apply changes |
| 37 | +Apply the refactoring rules to actually modify the code: |
| 38 | +```bash |
| 39 | +vendor/bin/rector process |
| 40 | +``` |
| 41 | + |
| 42 | +### Debug mode |
| 43 | +To see detailed information about what Rector is doing: |
| 44 | +```bash |
| 45 | +vendor/bin/rector process --dry-run --debug |
| 46 | +``` |
| 47 | + |
| 48 | +### Finding new rules |
| 49 | +To discover additional Rector rules for your project, visit: https://getrector.com/find-rule |
| 50 | + |
| 51 | +## Workflow |
| 52 | + |
| 53 | +1. **Before making changes**: Run `vendor/bin/phpstan analyse` to check current code quality |
| 54 | +2. **Use Rector for improvements**: Run `vendor/bin/rector process --dry-run` to preview automated fixes |
| 55 | +3. **Apply safe changes**: Run `vendor/bin/rector process` to apply the changes |
| 56 | +4. **Verify with tests**: Run `make test` to ensure changes don't break functionality |
| 57 | +5. **Final analysis**: Run `vendor/bin/phpstan analyse` to confirm improvements |
| 58 | + |
| 59 | +## CI/CD Integration |
| 60 | + |
| 61 | +Both PHPStan and Rector are integrated into the CI pipeline to ensure: |
| 62 | +- No new PHPStan errors are introduced (beyond the baseline) |
| 63 | +- Code follows modern PHP practices through Rector |
0 commit comments