PHPackages                             magento-ecg/coding-standard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. magento-ecg/coding-standard

ActivePhpcodesniffer-standard[Testing &amp; Quality](/categories/testing)

magento-ecg/coding-standard
===========================

A set of PHP\_CodeSniffer rules and sniffs.

4.5.4(3y ago)3091.7M↓20.5%95[1 issues](https://github.com/magento-ecg/coding-standard/issues)[1 PRs](https://github.com/magento-ecg/coding-standard/pulls)20MITPHPPHP ^7.1 || ^8.0

Since Nov 6Pushed 1y ago43 watchersCompare

[ Source](https://github.com/magento-ecg/coding-standard)[ Packagist](https://packagist.org/packages/magento-ecg/coding-standard)[ Docs](https://github.com/magento-ecg/coding-standard)[ RSS](/packages/magento-ecg-coding-standard/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)DependenciesVersions (19)Used By (20)

ECG Magento Code Sniffer Coding Standard
========================================

[](#ecg-magento-code-sniffer-coding-standard)

[![SensioLabsInsight Medal](https://camo.githubusercontent.com/5fe70b9361758ef798bc9d4505aed1a7aaaddd027e4525b323cc47d3983bb62f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f61303663333763362d306437392d343437362d616666352d3132643863653164386335332f6269672e706e67 "SensioLabsInsight Medal")](https://insight.sensiolabs.com/projects/a06c37c6-0d79-4476-aff5-12d8ce1d8c53)

ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for [PHP\_CodeSniffer](https://github.com/squizlabs/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 instantiation of Mage and Enterprise classes;
- unnecessary collection loading;
- excessive code complexity;
- use of dangerous functions;
- use of PHP Superglobals;

and many others.

Both Magento and Magento 2 are supported.

Installation
============

[](#installation)

Before starting using our coding standard install [PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).

The recommended installation method for PHPCS is globally with Composer:

```
composer global require "squizlabs/php_codesniffer=*"
```

Make sure Composer's bin directory (defaulted to `~/.composer/vendor/bin/`) is in your PATH.

Clone or download this repo somewhere on your computer or install it with [Composer](http://getcomposer.org/):

```
composer require magento-ecg/coding-standard
```

---

Note: PHP\_CodeSniffer 3.x is now required to run our coding standard. To install PHP\_CodeSniffer 2.x compatible version:

```
composer require magento-ecg/coding-standard:4.*
```

Add the ECG standards directory to PHP\_CodeSniffer's installed paths:

```
$ ./vendor/bin/phpcs --config-set installed_paths /path/to/your/folder/vendor/magento-ecg/coding-standard
```

You can check Installation by running following command:

```
$ ./vendor/bin/phpcs -i

```

It should do the following output:

```
The installed coding standards are EcgM2, PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12 and Magento2

```

Usage CLI Tool
==============

[](#usage-cli-tool)

Select a standard to run with CodeSniffer: EcgM2 for Magento 2

Run CodeSniffer:

```
$ ./vendor/bin/phpcs --standard=EcgM2,PSR2,Magento2 /path/to/code
```

This package is compatible with Composer Installer Plugins for PHPCS coding standards (such as ) and can be automatically registered with PHPCS during installation.

To check design templates, you must specify `phtml` in the `--extensions` argument: `--extensions=php,phtml`

Usage Hook pre-commit
=====================

[](#usage-hook-pre-commit)

Get hook file from the existing repository.

```
$ /path/to/your/folder/vendor/magento-ecg/coding-standard/.githooks
```

Install Hooks on the project. Copy hook into the project GIT folder

```
cp -R ./vendor/magento-ecg/coding-standard/.githooks ./

```

To automate hooks installation for all developers, it needs to include the following lines into your project's composer.json

```
    "scripts": {
        "post-install-cmd": [
            "git config core.hooksPath .githooks"
        ],
        "post-update-cmd": [
            "git config core.hooksPath .githooks"
        ]
    }

```

Run composer install to refresh the project state.

```
composer install

```

You are done! Now, each product commit will be validated for an alignment with Magento Coding Standards.

Usage PHPStorm
==============

[](#usage-phpstorm)

PhpStorm provides code style check through integration with the PHP Code Sniffer tool, which validates your code for consistency with a coding standard and best practices.

Once Tool installed and configured in PhpStorm, the tool is available in any opened PHP file. Errors and warnings reported by PHP Code Sniffer on-the-fly are displayed as popup messages.

Install coding standard for development *See Installation steps.*

**Configure PhpStorm**

- Open Preference: "Settings &gt; Preferences &gt; Editor &gt; Inspections &gt; PHP &gt; Quality Tools".
- Choose "PHP\_CodeSniffer validation" option.
- It is ok to configure everything under the scope "Everything else":
- In the "Check files with extensions" field, provide the comma-separated list of file extensions that should be checked by PHP Code Sniffer: php, js, phtml.
- Installed standard path should be checked and selected project path

```
/path/to/your/folder/vendor/magento-ecg/coding-standard

```

- Choose installed coding standard path as the main for standards
- Select "EcgM2" or "Custom" it the "Coding standard" list.

[![PHP Storm](image/php_storm.png)](image/php_storm.png)

Note: We would also suggest enabling PHP Mess Detector validation as well. Note: in case of using a Docker or VM, It needs to configure new PHPCS CLI Interpreter which will point out to VM/Docker.

Requirements
============

[](#requirements)

PHP 5.4 and up.

Checkout the `php-5.3-compatible` branch to get the PHP 5.3 version.

Contribution
============

[](#contribution)

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

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity60

Solid adoption and visibility

Community47

Growing community involvement

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~226 days

Recently: every ~130 days

Total

15

Last Release

1095d ago

Major Versions

1.2 → 2.02015-12-18

2.1 → 3.02017-06-17

3.1 → 4.02022-01-28

PHP version history (4 changes)1.0PHP &gt;=5.4.0

4.4.4PHP ^7.1

4.5.1PHP ^7.1||^8.1

4.5.4PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/472255?v=4)[Alex Zarichnyi](/maintainers/zlik)[@zlik](https://github.com/zlik)

![](https://avatars.githubusercontent.com/u/5476558?v=4)[Alex Karanda](/maintainers/alexkaranda)[@alexkaranda](https://github.com/alexkaranda)

---

Top Contributors

[![zlik](https://avatars.githubusercontent.com/u/472255?v=4)](https://github.com/zlik "zlik (50 commits)")[![zhooravlik](https://avatars.githubusercontent.com/u/1256891?v=4)](https://github.com/zhooravlik "zhooravlik (15 commits)")[![ovekeryk](https://avatars.githubusercontent.com/u/948224?v=4)](https://github.com/ovekeryk "ovekeryk (11 commits)")[![alexkaranda](https://avatars.githubusercontent.com/u/5476558?v=4)](https://github.com/alexkaranda "alexkaranda (10 commits)")[![alexkarand](https://avatars.githubusercontent.com/u/84372575?v=4)](https://github.com/alexkarand "alexkarand (9 commits)")[![davidwindell](https://avatars.githubusercontent.com/u/1720090?v=4)](https://github.com/davidwindell "davidwindell (3 commits)")[![philwinkle](https://avatars.githubusercontent.com/u/589550?v=4)](https://github.com/philwinkle "philwinkle (2 commits)")[![macieklewkowicz](https://avatars.githubusercontent.com/u/3532870?v=4)](https://github.com/macieklewkowicz "macieklewkowicz (2 commits)")[![lenaorobei](https://avatars.githubusercontent.com/u/17548019?v=4)](https://github.com/lenaorobei "lenaorobei (1 commits)")[![sreichel](https://avatars.githubusercontent.com/u/5022236?v=4)](https://github.com/sreichel "sreichel (1 commits)")[![tkn98](https://avatars.githubusercontent.com/u/10513307?v=4)](https://github.com/tkn98 "tkn98 (1 commits)")[![diazwatson](https://avatars.githubusercontent.com/u/1080386?v=4)](https://github.com/diazwatson "diazwatson (1 commits)")[![Zifius](https://avatars.githubusercontent.com/u/696727?v=4)](https://github.com/Zifius "Zifius (1 commits)")[![schmengler](https://avatars.githubusercontent.com/u/367320?v=4)](https://github.com/schmengler "schmengler (1 commits)")[![fballiano](https://avatars.githubusercontent.com/u/909743?v=4)](https://github.com/fballiano "fballiano (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")

### Embed Badge

![Health badge](/badges/magento-ecg-coding-standard/health.svg)

```
[![Health](https://phpackages.com/badges/magento-ecg-coding-standard/health.svg)](https://phpackages.com/packages/magento-ecg-coding-standard)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M360](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
