Code Monkey home page Code Monkey logo

coding-standards's Introduction

Magento Extension Quality Program Coding Standard

NOTE: Vaimo fork of EQP, no changes to be made to this repository other than tagging the TIP of the module!!!

Build Status

Magento EQP Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool.

It allows automatically check your code against some of the common Magento and PHP coding issues, like:

  • raw SQL queries;
  • SQL queries inside a loop;
  • direct class instantiation;
  • unnecessary collection loading;
  • excessive code complexity;
  • use of dangerous functions;
  • use of PHP superglobals;
  • code style issues

and many others.

Magento Extension Quality Program Coding Standard consists of two rulesets - MEQP1 for Magento and MEQP2 for Magento 2. Each of them contains the rules depending on the requirements of each version.

Installation

Install all dependencies via Composer:

$ composer create-project --repository=https://repo.magento.com magento/marketplace-eqp magento-coding-standard

You’re required to authenticate; see Get your authentication keys for details.

Usage

$ cd magento-coding-standard

Select the standard to run with PHP_CodeSniffer. To check Magento extension run:

$ vendor/bin/phpcs /path/to/your/extension --standard=MEQP1

To check Magento 2 extension run:

$ vendor/bin/phpcs /path/to/your/extension --standard=MEQP2

By default, PHP_CodeSniffer will check any file it finds with a .inc, .php, .js or .css extension. To check design templates you can specify --extensions=php,phtml option.

To check syntax with specific PHP version set paths to php binary dir:

$ vendor/bin/phpcs --config-set php7.0_path /path/to/your/php7
$ vendor/bin/phpcs --config-set php5.4_path /path/to/your/php5.4

Fixing Errors Automatically

PHP_CodeSniffer offers the PHP Code Beautifier and Fixer (phpcbf) tool. It can be used in place of phpcs to automatically generate and fix all fixable issues. We highly recommend run following command to fix as many sniff violations as possible:

$ vendor/bin/phpcbf /path/to/your/extension --standard=MEQP2

Dynamic Sniffs

Sniffs with complex logic, like MEQP2.Classes.CollectionDependency and MEQP2.SQL.CoreTablesModification require path to installed Magento 2 instance. You can specify it by running following command:

$ vendor/bin/phpcs --config-set m2-path /path/to/magento2

Notice: Dynamic sniffs will not work without specified m2-path configuration option.

Notice: Don't forget to clear cache folder in project root directory if you want to run sniffs for other Magento versions.

Marketplace Technical Review

To make sure your extension will pass CodeSniffer checks of Magento Marketplace Technical Review, you could run phpcs command with --severity=10 option.

$ vendor/bin/phpcs /path/to/your/extension --standard=MEQP2 --severity=10 --extensions=php,phtml

All severity 10 errors must be fixed in order to successfully pass Level 1 CodeSniffer checks.

Requirements

Notice: PHP and Composer should be accessible globally.

Contribution

Please feel free to contribute new sniffs or any fixes or improvements for the existing ones.

coding-standards's People

Contributors

chnorton avatar diazwatson avatar ihor-sviziev avatar ikruchynskyi avatar lenaorobei avatar moleman avatar nocturnalfrog avatar paweltatarczuk avatar pivulic avatar powli avatar rafaelstz avatar rud5g avatar t-richards avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

drsolomon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.