DEV Community

Cover image for How to Avoid Adding New Code that Uses Deprecated Code?
Henrik Gemal
Henrik Gemal

Posted on

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:

Mark Deprecated Code

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() {
}
Enter fullscreen mode Exit fullscreen mode

Install PHPStan Deprecation Plugin

Now install the PHPStan deprecation plugin from GitHub.

Generate a PHPStan Baseline

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 with CI

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay