Checking for Deprecated Code with the drupal-check Package


Post:2021/11/04

Update:2021/11/05

Server-side Other
bg
Checking for Deprecated Code with the drupal-check Package

Gabriel Seth Ente

Drupal’s core codebase is always changing, due in part to its contributors always looking to improve Drupal for developers. That means as more improvements are made, changes are made as well, and consequently, these changes cause code to become obsolete and ultimately, deprecated. Luckily, there are ways around this. Composer, Drupal’s prime tool for dependency management, is a great help in keeping your code up to date and ready. Another nice thing about it is that it’s great for getting help from the Drupal community. Enthusiastic third-party developers are usually willing to take matters into their own hands when asking for improvements, which bring us to our titular package, drupal-check.

Why drupal-check?

While many analysis tools exist for PHP, such as PHPStan, drupal-check stands out for being focused squarely on Drupal’s systems. What other tools would miss, drupal-check is more likely to pick up on any errors in your code. With more developers migrating their code from Drupal 7 and 8 onto 9, and maybe eventually Drupal 10, when that comes out, it’s becoming increasingly important that developers check their code as thoroughly as they can, and this tool could help. You can find drupal-check here.

How do I use it?

Well, first you have to install it. Wait, who is that? Oh, it’s our friend Composer, here to help us again. Using your command prompt, locate and change directories to that of your Drupal project, and use this command:

composer require mglaman/drupal-check --with-all-dependencies

It’s important to install it with its dependencies, since it does need quite a few. Once that’s done, you’re free to use the package, and using it is very simple. Insert the following command to use it:

php vendor\mglaman\drupal-check\drupal-check modules\webform

Allow me to explain the above command. When composer installs drupal-check, it is automatically placed in your vendor folder for easy use. So vendor\mglaman\drupal-check\drupal-check is locating where the command is to use it. The next part, modules\webform is the directory that drupal-check will be checking. Once that’s done, drupal-check will do the job of checking and analyzing the code for you.

Note: Try not to make the mistake of making drupal-check on a directory with heavy files underneath, for example, the entire modules folder, as it can cause errors

After drupal-check has finished checking, it will list down errors helpfully on the command prompt, for example:

drupal-check

If the check goes through without finding anything, a message telling you it’s okay will be displayed:

asdsad

What I have described is only the basic use for drupal-check. While it is probably it's most prominent feature, it does have other helpful features you can make good use of. It's not perfect, and it doesn't work perfectly, but it does the job most of the time, and can be incredibly helpful.

Profile picture for user Gabriel Seth Ente
Gabriel Seth Ente
Software Developer
I'm a beginner software developer, with dreams of broadening my horizons. Working at Acret has been an eye opener, and has been an incredibly positive experience. As I work and gain more experience, one day I will become a more confident contributor not just to my job, but other aspects of people's lives.