Refactor without breaking behavior (PHP)
Characterization tests, small mechanical steps, and clean-cut commits keeping refactors boring.
Track: 🧰 Engineering Essentials · Domain: Code Quality · Level: intermediate · ~35 min
Who this is for: All Software Engineers
When to Use This Skill
Characterization tests, small mechanical steps, and clean-cut commits keeping refactors boring. Use it whenever a matching task appears in conversation — the agent loads these instructions on demand.
Steps
- Pin current behavior with characterization tests where gaps exist
- Plan steps each leaving tests green; commit per step
- Prefer mechanical moves (extract, inline, rename) over clever rewrites
- Keep behavior changes in separate PRs from structure moves
- Measure complexity delta honestly; stop when readability peaks
- Leave the campsite cleaner but don't rebuild the forest
- Run static analysis (PHPStan/Psalm) at max level in CI
- Profile request cycles with Xdebug + cachegrind on real routes
Common Pitfalls
- Big-bang rewrites losing hidden behaviors
- 'While I'm here' feature creep inside refactor PRs
Commands
Install with skills CLI
npx skills add aniruddhaadak80/skills --skill code-quality-refactor-safely-php
Install globally
npx skills add aniruddhaadak80/skills --skill code-quality-refactor-safely-php -g
Part of aniruddhaadak80/skills · Browse all at https://skills.sh/aniruddhaadak80/skills