Technical Mid Level

How do you use static analysis tools like PHPStan or Psalm in a PHP project? What level do you run at and how do you handle legacy code?

Quick Tip

Show the adoption path: "I start at PHPStan level 5, generate a baseline for existing errors, and require zero new errors in CI. Then I raise the level one step at a time, fixing baseline errors as part of regular work."

What good answers include

PHPStan and Psalm analyse code without executing it, catching type errors, undefined methods, dead code, and logic bugs. Both have progressive levels — start at a low level and increase as the codebase improves. For legacy code: use baseline files to ignore existing errors and enforce zero new errors. Key features: generics for collection types, custom PHPDoc types, extension points for framework-specific rules, and CI integration to block merges with new errors. Strong candidates discuss: the practical difference between PHPStan and Psalm, how to handle dynamic frameworks (magic methods, facades), configuring return types for Doctrine repositories, and that static analysis catches different bugs than tests — both are needed.

What interviewers are looking for

Tests code quality discipline. Candidates who do not use static analysis are missing an entire category of bug prevention. Those who can describe a progressive adoption strategy with baselines demonstrate practical experience in real codebases.

← All PHP questions