PHP backend case study

Legacy PHP Refactoring Lab

Refactoring lab for improving legacy PHP through behavior protection, service extraction, safer structure, and incremental modernization.

Case study

Technical scope

Some repositories are private until the work is closed. Project scope, technical decisions, and operating scenarios are described on the page. I can discuss the code during a technical conversation.

01

Problem

  • Legacy PHP rarely allows safe big-bang rewrites because it is unclear which behaviors are accidental and which are part of the system contract.
  • The project shows a small-step strategy: freeze behavior first, extract a service next, then improve structure.
02

Technical decision

  • Characterization first, small seams, incremental cleanup.
  • legacy/ remains as the starting point so refactoring can be compared against original behavior.
  • src/Application is the target location for application services extracted from procedural code.
  • docs/ADR-001-refactoring-strategy.md acts as guardrails, while phpstan.neon is the entrypoint for gradually increasing quality strictness.
03

Result

  • Refactoring steps and behavior protection.
  • Scaffold with legacy/, src/Application, tests/Characterization, ADR guardrails, and phpstan.neon.
  • Defined first milestone for behavior-locking tests and extracting one application service.
  • Preparation for DTO, validation, and gradual static-analysis level increases.
04

Stack

  • Legacy / PHP / Refactor / Tests
  • composer install
  • composer test