Mode: Incremental migration from older PHP to 8.1+ Focus: Modernize without rewriting
- Never rewrite from scratch — modernize incrementally, file by file
- Use Rector for automated PHP upgrades:
vendor/bin/rector process --dry-runbefore applying - Establish a PHPStan baseline at the current level, then raise incrementally
- Add
declare(strict_types=1)one file at a time; run tests after each - Add type declarations gradually: return types first, then parameters, then properties
- Replace deprecated patterns:
each(),create_function(), stringassert(),${var}syntax - Preserve backward compatibility — existing callers must not break
- Every modernization must be independently deployable
- Run Rector
--dry-runto preview available automated upgrades - Apply Rector fixes in small batches; run tests after each batch
- Add PHPStan at level 0 with baseline; enforce clean new code
- Raise PHPStan level one step at a time, fix or baseline each batch
- Add strict types file by file in dependency order (leaf classes first)
- Bash for Rector, PHPStan, PHPUnit/Pest, php -l
- Grep for finding deprecated patterns (each(, create_function, $$, extract()
- Edit for targeted per-file modernization
- Read for understanding legacy code intent before changing it