PHP Sniffer & Beautifier extension for Visual Studio Code

Published June 19, 2023

Pixel art of a closeup of an eye looking through a magnifying glassIf you've been a user of Visual Studio Code for your custom Drupal development, then you're probably (hopefully) familiar with this documentation page that provides an overview of recommended extensions and configuration

In the past, I've recommended using the phpcs extension for integration with Visual Studio Code. I did this knowing full well that there haven't been any new commits to the extension's code since 2018! It worked fine, and it was also the recommended phpcs-related extension on the doc page mentioned above, so I didn't think about it too much.

Recently, in an effort to use phpcs and phpcbf in a slightly different way (more on that another time), I needed to find a more up-to-date extension - I found (and have been using for several months now) the PHP Sniffer & Beautifier extension. This includes all the necessary functionality to display coding standard issues in Visual Studio Code's Problems tab and has been better maintained the past few years (although the maintainer is looking for others to help). 

Here's my configuration when using a separate install of Drupal Coder (although different configurations are possible depending on your project and local development stack).

  /* PHP Sniffer & Beautifier */
 "phpsab.snifferEnable": true,
 "phpsab.executablePathCS": "/Users/michael/sites/drupal_coder/vendor/bin/phpcs",
 "phpsab.fixerEnable": true,
 "phpsab.executablePathCBF": "/Users/michael/sites/drupal_coder/vendor/bin/phpcbf",
 "phpsab.standard": "/Users/michael/sites/drupal_coder/phpcs.xml",
 "phpsab.snifferMode": "onType",
 "phpsab.debug": false,
 "phpsab.fixerArguments": [],

If you're a Visual Studio Code user and you utilize phpcs and phpcbf as part of your everyday workflow, you may want to consider using this module. 

DrupalEasy's Professional Module Development course (Full version) includes configuring both Visual Studio Code and PhpStorm to integrate phpcs, phpcbf, and PhpStan in an efficient manner.

The pixel art image used in this blog post was generated by the DALL-E project of OpenAI.

Add new comment

The content of this field is kept private and will not be shown publicly.

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!