PHPackages                             space48/magento2-code-quality - 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. space48/magento2-code-quality

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

space48/magento2-code-quality
=============================

Provides rulesets for phpmd, phpcs and eslint that overrides some Magento sniffs and provides some new ones as well

1.3.2(6mo ago)52.0k↓50%8[2 PRs](https://github.com/Space48/magento2-code-quality/pulls)proprietaryPHPPHP ^8

Since Apr 8Pushed 6mo ago12 watchersCompare

[ Source](https://github.com/Space48/magento2-code-quality)[ Packagist](https://packagist.org/packages/space48/magento2-code-quality)[ RSS](/packages/space48-magento2-code-quality/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (28)Used By (0)

Space48 Code Quality tool
=========================

[](#space48-code-quality-tool)

A module that helps to easily apply static code analysers to the project's code. It uses [grumphp](https://github.com/phpro/grumphp) under the hood with a predefined set of rules based on Magento 2 coding standards but tuned to be less annoying!

Usage
-----

[](#usage)

### Usage on a regular Space48 Warden based Magento 2 project:

[](#usage-on-a-regular-space48-warden-based-magento-2-project)

After pulling and installing/updating project locally run following command to update local git hooks and install npm packages:

```
make linters-init
```

It will add precommit git hook, so on each commit linters will run for the files added to commit.

### Git Pre-Commit

[](#git-pre-commit)

A commit will fail if linters found errors in your code, check the '*console*' tab in 'Git' section of the PhpStorm for errors output by linters. Fix all errors and commit again.

**Warning**By default Autofix feature is turned ON. Once you try to commit, linters will automatically fix some errors. Double check changes after.

When fixing errors, to see predicted linters output you can instead of trying to commit again just run manually from console:

```
make precommit
```

### Usage on other projects

[](#usage-on-other-projects)

Run `vendor/bin/grumphp git:init` to add githook Grumphp will sniff your code on any git commit

### Ignoring Rules

[](#ignoring-rules)

in the linters output you will see hints with rule names being violated. If for some reason you can not fix violated rule feel free to ignore it using Suppress Warning comment corresponding concrete linter type (see hints in output or google).

**IMPORTANT!**When ignoring a rule in the code always add a comment with the reason of why you had ignored it instead of fixing.

### Finetuning

[](#finetuning)

Rules can be tuned with parameters, excluded completely or rewritten on a Project Level using the `ruleset.xml, phpmd.xml, .eslintrc, .stylelint` files in the project's root folder and committing them to project's repo.

If you think everyone can benefit from your rules changes - feel free to create a PR.

### CI Integration

[](#ci-integration)

To add Code Quality to Bitbucket pipelines as a mandatory step do following.

#### Edit Makefile

[](#edit-makefile)

Add new command to makefile:

```
analyse-ci:
    git fetch --shallow-since=01/09/2021
    git diff 111999..HEAD | vendor/phpro/grumphp/bin/grumphp run

```

'111999' - is your starting commit hash

#### Configure bitbucket-pipelines.yml

[](#configure-bitbucket-pipelinesyml)

Add new step to your build like this:

```
- step: &code-quality
        name: "Code Quality"
        script:
          - if [ ! -f grumphp.yml ] || [ ! -d vendor/space48/magento2-code-quality ]; then printf 'No Space48 Code quality module found'; exit; fi
          - /bin/bash -c "[ $(grep '^[ ]*eslint:' grumphp.yml) ] || [ $(grep '^[ ]*stylelint:' grumphp.yml) ] && source vendor/space48/magento2-code-quality/script/npm-install.sh"
          - make analyse-ci

```

#### Check locally

[](#check-locally)

To run linters as it would run on CI (from starting commit till HEAD):

```
make analyse
```

#### Automatically fix some errors

[](#automatically-fix-some-errors)

Use any of this options:

Option 1: Set `fixer/enabled` and `fixer/fix_by_default` to **true** in grumphp.yml file

Option 2: Run command `vendor/phpro/grumphp/bin/grumphp run` with '--fix' option

```
vendor/phpro/grumphp/bin/grumphp run --fix
```

Installation
------------

[](#installation)

Add Code Quality tool to the Magento Project:

### Warning!

[](#warning)

Eslisnt and Stylelint requires **NodeJs v10** or higher.

### Installation on a regular *Space48 Warden based Magento 2* project:

[](#installation-on-a-regular-space48-warden-based-magento-2-project)

On Magento versions **earlier than 2.4** add following to 'require' section of project's `composer.json`:

```
"require": {
  ...
  "symfony/options-resolver": "v2.8.52 as 4.4"
}

```

#### 1. Run following commands from project root:

[](#1-run-following-commands-from-project-root)

Add the module

```
warden env exec php-fpm composer require --dev space48/magento2-code-quality
```

When it will ask for 'grumphp.yml' creation - answer `no`:

```
Do you want to create a grumphp.yml file? [Yes]: no
```

Copy files and install npm packages:

```
warden env exec php-fpm chmod +x vendor/space48/magento2-code-quality/script/install.sh
warden env exec php-fpm ./vendor/space48/magento2-code-quality/script/install.sh
```

Add git precommit hook:

```
chmod +x vendor/space48/magento2-code-quality/script/add-hook.sh
vendor/space48/magento2-code-quality/script/add-hook.sh
```

Create `.git` folder in warden:

(*You can mount .git volume from host to inside container instead, but `grumphp` only requires empty .git folder, no much sense in syncronizing all .git/\* files adding even more overhead for mutagen.*)

```
warden env exec php-fpm /bin/bash -c '[ -d .git ] || mkdir .git'
```

Add configuration files to git:

```
git add ruleset.xml phpmd.xml .eslintrc .stylelintrc grumphp.yml
```

#### 2. Add following to project`s 'Makefile':

[](#2-add-following-to-projects-makefile)

```
### Code Quality section
CQ_STARTING_COMMIT_HASH='a000z999'
CQ_STARTING_COMMIT_DATE='01/01/2021'

-include 'vendor/space48/magento2-code-quality/code-quality.mk'
```

(*If you don`t have 'vendor' under VCS - copy vendor/space48/magento2-code-quality/code-quality.mk file somewhere to your project and link it from there*)

It contains following commands:

- `linters-init` - init linters on local machine
- `analyse` - analyses all code from starting commit hash to HEAD
- `analyse-fix` - analyses all code from starting commit hash to HEAD and fixes autofixable errors
- `precommit` - analyses code staged for commit
- `precommit-fix` - analyses code staged for commit and fixes autofixable errors
- `analyse-ci` - Same as 'analyse' but modified to be called during build on CI env

Update `CQ_STARTING_COMMIT_HASH` variable. Replace the sample `a000z999` commit hash with the hash from the project where you want to start linting from. Files modified after the starting commit hash will be linted during project build and will fail the build on linter violations.

Update `CQ_STARTING_COMMIT_DATE` variable. Replace sample `01/01/2021` date with the date of the Starting Commit (specified at `CQ_STARTING_COMMIT_HASH` variable). This is required because CI uses shallow git clone.

**Note:**If using warden, commit still fails with `SplFileInfo::openFile(/var/www/html/.git/COMMIT_EDITMSG): failed to open st   ream: No such file or directory` error: rename or revert to original git 'commit-msg' hook.

#### 3. Commit to project`s repo.

[](#3-commit-to-projects-repo)

Commit updated composer files, vendor folder, code-quality config files from the root and 'makefile' changes

### Installation on any other Magento 2 project:

[](#installation-on-any-other-magento-2-project)

1. add module `space48/code-quality` via Composer
2. run `vendor/space48/code-quality/script/install.sh` script to copy necessary files and install npm packages
3. in `grumphp.yml` remove configs marked as `(remove on non warden environment)`
4. run `vendor/bin/grumphp git:init` to update precommit hooks

Configuration
-------------

[](#configuration)

Whitelist/exclude folders can be configured at `{project_root}/grumphp.yml`:

```
phpmd:
    whitelist_patterns:
        - /^app/
    triggered_by: [ 'php', 'phtml' ]
    exclude: [ ]
phpcs:
    whitelist_patterns:
        - /^app/
    triggered_by: [ 'php', 'phtml' ]
    ignore_patterns: [ ]
eslint:
    triggered_by: [ js, jsx, ts, tsx, vue ]
    whitelist_patterns: [ /^app/ ]
```

To turn off whole linter type (for example 'eslint') - remove or comment out corresponding 'task' section.

Linter rules can be finetuned on a project level by editing `ruleset.xml, phpmd.xml, .eslintrc, .stylelint` files. See `Space48/code-quality/rulesets/` for examples.

Some rules can be overwritten on a class level. See `rulesets/PhpMd/extra.xml` for examples.

More info
---------

[](#more-info)

For more info and for Configuration help refer to [grumphp repo](https://github.com/phpro/grumphp) docs.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance69

Regular maintenance activity

Popularity28

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 91.3% of commits — single point of failure

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 ~67 days

Recently: every ~145 days

Total

26

Last Release

181d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fc6deb604a4a18e3d7b9f8d73a8ad52bd8f9556e6d84f6fb0ee76eeee65b330?d=identicon)[space48](/maintainers/space48)

---

Top Contributors

[![stkec](https://avatars.githubusercontent.com/u/3246277?v=4)](https://github.com/stkec "stkec (63 commits)")[![asuchalkin-space48](https://avatars.githubusercontent.com/u/72035419?v=4)](https://github.com/asuchalkin-space48 "asuchalkin-space48 (2 commits)")[![IgorM92](https://avatars.githubusercontent.com/u/7593380?v=4)](https://github.com/IgorM92 "IgorM92 (2 commits)")[![tgerulaitis](https://avatars.githubusercontent.com/u/613076?v=4)](https://github.com/tgerulaitis "tgerulaitis (2 commits)")

---

Tags

standards

### Embed Badge

![Health badge](/badges/space48-magento2-code-quality/health.svg)

```
[![Health](https://phpackages.com/badges/space48-magento2-code-quality/health.svg)](https://phpackages.com/packages/space48-magento2-code-quality)
```

###  Alternatives

[wp-coding-standards/wpcs

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

2.8k42.5M1.6k](/packages/wp-coding-standards-wpcs)[dealerdirect/phpcodesniffer-composer-installer

PHP\_CodeSniffer Standards Composer Installer Plugin

598161.9M1.9k](/packages/dealerdirect-phpcodesniffer-composer-installer)[phpcompatibility/phpcompatibility-wp

A ruleset for PHP\_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.

22130.6M587](/packages/phpcompatibility-phpcompatibility-wp)[phpcsstandards/phpcsextra

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

10324.3M44](/packages/phpcsstandards-phpcsextra)[acquia/coding-standards

PHP\_CodeSniffer rules (sniffs) for Acquia coding standards

214.8M28](/packages/acquia-coding-standards)[ec-europa/qa-automation

Extra php codesniffs for QualityAssurance.

10290.4k3](/packages/ec-europa-qa-automation)

PHPackages © 2026

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