Home >Backend Development >PHP Tutorial >How to Avoid Adding New Code that Uses Deprecated Code?
Spring cleaning your code? Developers are constantly improving code and adding new features. Sometimes, this includes deprecating older code as newer, faster alternatives become available. However, it's not always feasible to immediately update all instances where the deprecated code is used.
At DinnerBooking, we've tackled this challenge using PHPStan. Here’s how:
First, ensure all deprecated code is clearly marked so that static code analyzers like PHPStan can identify it. Typically, it looks like this:
/** * @deprecated */ function count() { }
Now install the PHPStan deprecation plugin from GitHub.
Generate a baseline that identifies all instances of deprecated code. You can do this by adding --generate-baseline to your PHPStan command. The baseline is saved in phpstan-baseline.neon.
Integrate this baseline into your CI pipeline to ensure that no new code referencing deprecated code is introduced.
By following these steps, we ensure that our codebase remains clean and maintainable, preventing the addition of new code that relies on deprecated functions.
The above is the detailed content of How to Avoid Adding New Code that Uses Deprecated Code?. For more information, please follow other related articles on the PHP Chinese website!