Check your version
This tutorial covers a topic in Drupal 8 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 8, but we consider it archived.
Implementing the Drupal coding standards is important, and shouldn't be ignored. But doing so can be a bit tedious. Especially when you're first getting started. There are a lot of rules to learn, and maybe even some old habits to break. So it's understandable that you might not get it perfect every time. Having your work sent back to you by a reviewer because you formatted a comment incorrectly, or placed a closing bracket on the wrong line, can be frustrating. Luckily there are all kinds of great tools to help us automate the review process. Letting us scan our own code, or that written by others for coding standards violations, and getting them fixed right away.
While the content of this tutorial is based on Drupal 7 most of the same tools, and techniques, will work just fine with other versions of Drupal.
The JetBrains website has the most up-to-date information about configuring PhpStorm to work with Drupal. https://confluence.jetbrains.com/display/PhpStorm/Drupal+Development+us…
In this tutorial we'll look at a few different ways that we can automate our coding standards reviews using tools that read in our PHP code, and apply a set of predefined rules in order to help point out mistakes. We'll start by looking at the Coder module and the UI that it provides. Then, we'll install
PHP_CodeSniffer, and use that in conjunction with the rules contained in the Coder module, and the drush command line utility, to run coding standards reviews at the command line. And, in some cases even in our IDE's that support PHPCS.
Since there are a handful of commands to execute, here is the walkthrough on installing and using PHPCS + drush.
This command downloads the coder module globally. Instead of putting it in the Drupal module's directory, you're downloading it to the ~/.drush/ directory. Since this is in your drush $PATH it's globally available and you can use it on any project without having to install coder on every Drupal project you work on.
drush pm-download coder --destination=$HOME/.drush
You then need to clear the internal drush cache so that it locates the new command contained in the just installed coder module.
drush cache-clear drush
Then, you need to install phpcs. There are a lot of ways to install it, and depending on your environment you might even already have it installed. Check with:
If you don't, the easiest way to install it is with drush:
Then you can check an individual file, or a directory, for coding standards violations with:
drush drupalcs path/to/code
Over the years we've developed some techniques for practicing that we wanted to share. At Drupalize.Me we take hugging seriously. In this tutorial we'll look at the art, and science, of giving a good hug. The Merriam Webster dictionary defines the word hug as; squeeze (someone) tightly in one's arms, typically to express affection.
Did you know there are all kinds of different hugs that you can give? In this tutorial we'll look at:
- Defining what a hug is
- Some of the many types of hugs in the world today
- Precautions you may want to familiarize yourself with before hugging
- And the importance of proper technique
Lets go ahead and get started shall we?