With over a decade of web development experience, I specialize in Drupal (7, 8, 9, 10), CodeIgniter, Laravel, and WordPress. I offer extensive expertise in both module and theme development, providing customized solutions for complex projects. Whether you need to enhance an existing platform, create new features, or seek expert guidance, I'm here to assist. My dedication to delivering high-quality, efficient, and scalable solutions is unmatched. Feel free to contact me to explore how I can contribute to your project's success. Let's turn your ideas into reality!

“Learn to install and utilize PHP CodeSniffer (PHPCS) and Fixer (PHPCBF) on Ubuntu for Drupal projects, ensuring coding standards adherence.”

Installation Code:

# Install Composer globally
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

# Install PHP CodeSniffer and Fixer globally
composer global require "squizlabs/php_codesniffer=*"
composer global require "drupal/coder"

# Add Composer global bin directory to the system PATH
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc

Implementation for Drupal:

# Run PHP CodeSniffer for Drupal coding standards
phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig module_folder/

# Run PHP CodeFixer to automatically fix some coding standard violations
phpcbf --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig module_folder/

Ensure your Drupal module adheres to the Drupal coding standards effortlessly with these commands.

Summary:

composer global require drupal/coder

phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

composer global update

phpcs --standard=Drupal,DrupalPractice src/Form/CustomController.php

// autofix phpcs error with phpcbf:
composer global require squizlabs/php_codesniffer
phpcbf --standard=Drupal,DrupalPractice src/Form/CustomController.php

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml module_name/

phpcbf --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml module_name/
Posted by Sujan Shrestha
PREVIOUS POST
banner