How to check for code deprecations in Drupal

Since Drupal 8, the community is actively updating the source code. Deprecations are something to deal with. This blog post shows you how to monitor your code.

There is a simple way for checking. The drupal-check package will inspect your code:

composer require mglaman/drupal-check --dev

 Now run

 drupal-check -a web/modules/custom

The result was the following:

 ------ ----------------------------------------------------------------------
  Line   alter_entity_autocomplete/src/EntityAutocompleteMatcher.php
 ------ ----------------------------------------------------------------------
  28     Cannot call method getReferenceableEntities() on object|false.
  35     Call to an undefined static method Drupal::entityManager().
  36     Call to an undefined static method Drupal::entityManager().
 ------ ----------------------------------------------------------------------

Now look up de the deprecation, fix it and run again! :)