e-Zest members share technology ideas to foster digital transformation.

How to configure Magento2 coding standards with NetBeans 8.0?

Written by Pravin Patil | Feb 21, 2018 6:20:22 AM

It goes without saying that the software we deliver to customers should be of high quality. Our products need to look great, and help customers run their business. This is only feasible with a good and clean code!

While dealing with enterprise level software, the code quality needs to be both persistent and consistent throughout which involves writing and maintaining thousands and thousands of lines of code under the hood. With multiple developers working, it becomes really essential to have a good quality and readable code for smooth implementation and maintenance. It’s always a good practice to maintain standard coding practices to improve the code quality, scalability and maintainability of the application.

Especially on an enterprise level, a good quality code always makes it easier to employ a modular approach towards deployment. Considering all these necessary factors towards software development. We have various sophisticated IDEs, with very useful ‘intellisense’ abilities at hand, for an easy ride towards application building.

One such amazing editor tool is NetBeans IDE. It’s an easy to use package with all the needed features bundled together for making a developer’s life easy and secure! One of the most interesting features is its configuration for coding standards through a sophisticated approach towards documenting and writing the code.

I have tried to put down a detailed stepwise guide which will help you through configuring the coding standards with NetBeans and Magento 2.

Follow the steps below:

Prerequisites:

  • Ubuntu 16.04
  • NetBeans 8.0
  • phpcs 3.2.2
  • composer 1.0.0

Step1: Setup PHPCS

You can follow the installation guide listed in https://github.com/squizlabs/PHP_CodeSniffer
apt-get upgrade
apt-get install php-pear
pear install PHP_CodeSniffer
Make sure that phpcs is installed using below command
phpcs --version

 

Step2: Download and setup Magento2 coding standards (Magento EQP)

Clone or download library from https://github.com/magento/marketplace-eqp under /opt folder
cd /opt
git clone https://github.com/magento/marketplace-eqp.git
cd marketplace-eqp
composer install
It will create vendor folder under /opt/marketplace-eqp

Step3: Confirm that PHPCS and Magento EQP are installed properly on your machine.

cd /opt/marketplace-eqp
Set magento 2 coding standards with phpcs
phpcs --config-set installed_paths /opt/marketplace-eqp/
To check available coding standards using this command & it will display output like
phpcs -i

In the above output you can see that MEQP1(Magento 1) and MEQP2 (Magento 2) standards are configured

Step4: Configure Magento2 coding standard library with NetBeans

Open NetBeans editor and go to Tools->Plugin and make sure that you have installed phpcs plugin

Now configure PHPCS with NetBeans using Tools->Option->PHP->PHPCSMD and make sure that following options are configured properly

  • check file on open checkbox should be checked
  • update on save checkbox should be checked
  • phpcs script location should be properly specified (eg. /usr/local/bin/phpcs)
  • --standards should be ‘MEQP2’

Step5: Verify magento 2 coding standards

Goto Windows->’Action Items’ you will see phpcs coding issues in action window. See below screenshots for proper illustration of steps

Above steps should set up your configuration with the IDE.

I hope this blog helps you configure the Magento2 coding standards with Netbeans IDE and inspires you to follow the best coding standards, always! You are good to start!