PHPackages                             magento/magento-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/magento-coding-standard

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

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

A set of Magento specific PHP CodeSniffer rules.

40(2mo ago)37113.4M—7.7%164[64 issues](https://github.com/magento/magento-coding-standard/issues)[30 PRs](https://github.com/magento/magento-coding-standard/pulls)20OSL-3.0PHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Mar 27Pushed 2mo ago345 watchersCompare

[ Source](https://github.com/magento/magento-coding-standard)[ Packagist](https://packagist.org/packages/magento/magento-coding-standard)[ RSS](/packages/magento-magento-coding-standard/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (46)Used By (20)

Magento Coding Standard
=======================

[](#magento-coding-standard)

A set of Magento rules for [PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) tool.

Installation within a Magento 2 site
------------------------------------

[](#installation-within-a-magento-2-site)

To use within your Magento 2 project you can use:

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

Due to security, when installed this way the Magento standard for phpcs cannot be added automatically. You can achieve this by adding the following to your project's `composer.json`:

```
"scripts": {
    "post-install-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ],
    "post-update-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ]
}
```

### Installation for development

[](#installation-for-development)

You can install Magento Coding Standard by cloning this GitHub repo:

```
git clone git@github.com:magento/magento-coding-standard.git
cd magento-coding-standard
composer install
```

It is possible also to install a standalone application via [Composer](https://getcomposer.org)

```
composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard
```

### Verify installation

[](#verify-installation)

Command should return the list of installed coding standards including Magento2.

```
vendor/bin/phpcs -i
```

Usage
-----

[](#usage)

Once installed, you can run `phpcs` from the command-line to analyze your code `MyAwesomeExtension`

```
vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension
```

### Fixing issues automatically

[](#fixing-issues-automatically)

Also, you can run `phpcbf` from the command-line to fix your code `MyAwesomeExtension` for warnings like "PHPCBF CAN FIX THE \[0-9\]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY"

```
vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension
```

Contribution
------------

[](#contribution)

See the community [contribution model](https://github.com/magento/magento-coding-standard/blob/develop/.github/CONTRIBUTING.md).

### Where to contribute

[](#where-to-contribute)

- Documentation of existing rules. See [ExtDN PHP CodeSniffer rules for Magento 2](https://github.com/extdn/extdn-phpcs) as a good example.
- Bug fixes and improvements of existing rules.
- Creation of new PHP CodeSniffer rules.
- Discussions on new rules (through periodic hangouts or discussions per GitHub issue).

### How to contribute

[](#how-to-contribute)

1. Start with looking into [Community Dashboard](https://github.com/magento/magento-coding-standard/projects/1). Any ticket in `Up for grabs` is a good candidate to start.
2. Didn't satisfy your requirements? [Create one of three types of issues](https://github.com/magento/magento-coding-standard/issues/new/choose):
    - **Bug report** - Found a bug in the code? Let us know!
    - **Existing rule enhancement** - Know how to improve existing rules? Open an issue describe how to enhance Magento Coding Standard.
    - **New rule proposal** - Know how to improve Magento ecosystem code quality? Do not hesitate to open a proposal.
3. The issue will appear in the `Backlog` column of the [Community Dashboard](https://github.com/magento/magento-coding-standard/projects/1). Once it will be discussed and get `accepted` label the issue will appear in the `Up for grabs` column.

Testing
-------

[](#testing)

All rules should be covered by unit tests. Each `Test.php` class should be accompanied by a `Test.inc` file to allow for unit testing based upon the PHP\_CodeSniffer parent class `AbstractSniffUnitTest`. You can verify your code by running

```
vendor/bin/phpunit
```

Also, verify that the sniffer code itself is written according to the Magento Coding Standard:

```
vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php
```

### ESLint

[](#eslint)

Prerequisites: [Node.js](https://nodejs.org/) (`^12.22.0`, `^14.17.0`, or `>=16.0.0`).

You need to run the following command to install all the necessary packages described in the `package.json` file:

```
npm install
```

You can execute ESLint as follows:

```
npm run eslint -- path/to/analyze
```

### RECTOR PHP

[](#rector-php)

From `magento-coding-standard` project, you can execute rector php as follows:

```
vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php
```

The rules from rector that are applied are set inside the config file: `rector.php`

The option `--dry-run` displays errors found, but code is not automatically fixed.

To run rector for `magento` projects you need to:

- Specify the magento path and the autoload file for the magento project:

```
vendor/bin/rector process MAGENTO_PATH --dry-run --autoload-file MAGENTO_AUTOLOAD_FILE
```

Example:

```
vendor/bin/rector process magento2ce/app/code/Magento/Cms/Model --dry-run --autoload-file magento2ce/vendor/autoload.php
```

License
-------

[](#license)

Each Magento source file included in this distribution is licensed under the OSL-3.0 license.

Please see [LICENSE.txt](https://github.com/magento/magento-coding-standard/blob/master/LICENSE.txt) for the full text of the [Open Software License v. 3.0 (OSL-3.0)](https://opensource.org/licenses/osl-3.0.php).

###  Health Score

76

—

ExcellentBetter than 100% of packages

Maintenance82

Actively maintained with recent releases

Popularity68

Solid adoption and visibility

Community57

Growing community involvement

Maturity90

Battle-tested with a long release history

 Bus Factor4

4 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 ~61 days

Recently: every ~110 days

Total

42

Last Release

73d ago

Major Versions

1.0.2 → 2.0.02019-04-17

PHP version history (8 changes)1.0.0PHP &gt;=5.6.0

7PHP &gt;=7.3

27PHP ^8.1||^8.2

30PHP &gt;=7.4

32PHP ~8.1.0 || ~8.2.0

33PHP ~8.1.0 || ~8.2.0 || ~8.3.0

36PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

39PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/dbcf615f9bf1c6b766e11376c5e76245da3b22bfc132da6a85c1e185f31ddd26?d=identicon)[mage2-team](/maintainers/mage2-team)

---

Top Contributors

[![svera](https://avatars.githubusercontent.com/u/2188119?v=4)](https://github.com/svera "svera (199 commits)")[![lenaorobei](https://avatars.githubusercontent.com/u/17548019?v=4)](https://github.com/lenaorobei "lenaorobei (163 commits)")[![sivaschenko](https://avatars.githubusercontent.com/u/2028541?v=4)](https://github.com/sivaschenko "sivaschenko (121 commits)")[![loginesta](https://avatars.githubusercontent.com/u/1092519?v=4)](https://github.com/loginesta "loginesta (110 commits)")[![eliseacornejo](https://avatars.githubusercontent.com/u/16324697?v=4)](https://github.com/eliseacornejo "eliseacornejo (96 commits)")[![fredden](https://avatars.githubusercontent.com/u/334786?v=4)](https://github.com/fredden "fredden (37 commits)")[![sidolov](https://avatars.githubusercontent.com/u/11355520?v=4)](https://github.com/sidolov "sidolov (34 commits)")[![jcuerdo](https://avatars.githubusercontent.com/u/3788579?v=4)](https://github.com/jcuerdo "jcuerdo (34 commits)")[![glo71317](https://avatars.githubusercontent.com/u/85922880?v=4)](https://github.com/glo71317 "glo71317 (28 commits)")[![konarshankar07](https://avatars.githubusercontent.com/u/39480008?v=4)](https://github.com/konarshankar07 "konarshankar07 (26 commits)")[![jean-bernard-valentaten](https://avatars.githubusercontent.com/u/22167006?v=4)](https://github.com/jean-bernard-valentaten "jean-bernard-valentaten (25 commits)")[![djadobe16](https://avatars.githubusercontent.com/u/175836744?v=4)](https://github.com/djadobe16 "djadobe16 (22 commits)")[![ihor-sviziev](https://avatars.githubusercontent.com/u/1873745?v=4)](https://github.com/ihor-sviziev "ihor-sviziev (17 commits)")[![diazwatson](https://avatars.githubusercontent.com/u/1080386?v=4)](https://github.com/diazwatson "diazwatson (15 commits)")[![bubasuma](https://avatars.githubusercontent.com/u/8973208?v=4)](https://github.com/bubasuma "bubasuma (12 commits)")[![Rrego6](https://avatars.githubusercontent.com/u/5743402?v=4)](https://github.com/Rrego6 "Rrego6 (11 commits)")[![victor-v-rad](https://avatars.githubusercontent.com/u/106504?v=4)](https://github.com/victor-v-rad "victor-v-rad (11 commits)")[![anzin](https://avatars.githubusercontent.com/u/30952336?v=4)](https://github.com/anzin "anzin (10 commits)")[![Atul-glo35265](https://avatars.githubusercontent.com/u/138226841?v=4)](https://github.com/Atul-glo35265 "Atul-glo35265 (10 commits)")[![veloraven](https://avatars.githubusercontent.com/u/3596213?v=4)](https://github.com/veloraven "veloraven (7 commits)")

---

Tags

coding-standardmagentophpphp-codesniffer

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[wp-coding-standards/wpcs

PHP\_CodeSniffer rules (sniffs) to enforce WordPress coding conventions

2.7k42.5M1.6k](/packages/wp-coding-standards-wpcs)[slevomat/coding-standard

Slevomat Coding Standard for PHP\_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.

1.5k123.5M1.8k](/packages/slevomat-coding-standard)[phpcsstandards/phpcsextra

A collection of sniffs and standards for use with PHP\_CodeSniffer.

10224.3M44](/packages/phpcsstandards-phpcsextra)[mrpunyapal/rector-pest

Rector upgrade rules for Pest - refactoring and best practices for Pest testing framework

4717.6k18](/packages/mrpunyapal-rector-pest)

PHPackages © 2026

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