PHPackages                             maarsson/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. maarsson/coding-standard

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

maarsson/coding-standard
========================

Centralized custom coding standards applied across my projects

1.2.2(4mo ago)0121MITShellPHP ^8.4CI passing

Since Jan 9Pushed 4mo agoCompare

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

READMEChangelog (3)Dependencies (4)Versions (11)Used By (1)

maarsson/coding-standard
========================

[](#maarssoncoding-standard)

Centralized custom coding standards that can be applied across my different projects.

[![Latest Stable Version](https://camo.githubusercontent.com/6d20a0487c948a824e6fc9117152f0bc5a225891d763bc0dc95c22b4af296545/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6d61617273736f6e2f636f64696e672d7374616e646172643f6c6162656c3d4c6174657374)](https://github.com/maarsson/coding-standard/releases)[![Minimum PHP Version](https://camo.githubusercontent.com/bcf71d14b31dee7e934938e5950814bc4854bddcfd87ae833ce73dc7844be834/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6d61617273736f6e2f636f64696e672d7374616e646172642f7068702e737667)](https://camo.githubusercontent.com/bcf71d14b31dee7e934938e5950814bc4854bddcfd87ae833ce73dc7844be834/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6d61617273736f6e2f636f64696e672d7374616e646172642f7068702e737667)[![Tested on PHP 8,4 to 8.5](https://camo.githubusercontent.com/432d19ed828bf1b7d20c69d8ed11d3cd19736e64cd3b97c4c47fa3381892bc7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7465737465642532306f6e2d504850253230382e34253230253743253230382e352d627269676874677265656e2e7376673f6d61784167653d32343139323030)](https://github.com/maarsson/coding-standard/actions/workflows/ci.yml)[![Test](https://github.com/maarsson/coding-standard/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/maarsson/coding-standard/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/31ef6fb67c698746df80486b721837b11028cab8f5a65595d539c5b437f7f2a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d61617273736f6e2f636f64696e672d7374616e64617264)](https://github.com/maarsson/coding-standard/blob/master/LICENSE)

Note

See also [maarsson/dev-tools](https://github.com/maarsson/dev-tools).

About
-----

[](#about)

This package provides shared code quality rulesets and a sync script that applies them to consumer projects in a predictable and consistent way.

By following the installation steps below, the rulesets are automatically applied after composer install and composer update in your project. This guarantees that all projects use the exact same ruleset versions.

Currently supported:

- [PHP Mess Detector (PHPMD)](https://phpmd.org/) - detect design and complexity issues
- [PHP CodeSniffer (PHPCS)](https://github.com/PHPCSStandards/PHP_CodeSniffer/) - detect coding standard violations
- [PHP CS Fixer](https://cs.symfony.com/) - automatically enforce modern code style

---

Requirements
------------

[](#requirements)

- PHP ^8.4
- Composer

---

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

[](#installation)

### 1. Package installation

[](#1-package-installation)

Install the package as a development dependency in your project:

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

---

### 2. Project configuration (required)

[](#2-project-configuration-required)

To ensure the coding standards are applied automatically, you must configure Composer scripts in the target project.

#### 2.1. Add a named sync script

[](#21-add-a-named-sync-script)

In your project’s `composer.json` add:

```
{
  "scripts": {
    "coding-standard:sync": [
      "vendor/bin/sync-coding-standards.php"
    ]
  }
}
```

#### 2.2. Run the sync script on install and update

[](#22-run-the-sync-script-on-install-and-update)

Extend your project’s `composer.json` scripts section to include:

```
{
  "scripts": {
    "coding-standard:sync": [
      "vendor/bin/sync-coding-standards.php"
    ],
    "post-install-cmd": [
      "@coding-standard:sync"
    ],
    "post-update-cmd": [
      "@coding-standard:sync"
    ]
  }
}
```

With this setup, the coding standards are applied automatically.

---

When does it apply?
-------------------

[](#when-does-it-apply)

Once configured, the sync script runs automatically in the following cases:

Automatic execution:

- After composer install
- After composer update
- During CI pipelines that run composer install or composer update

Manual execution:

- You can also apply the coding standards manually at any time:

    `composer coding-standard:sync` (preferred)

    or:

    `./vendor/bin/sync-coding-standards.php` (direct execution)

---

What does the sync script do?
-----------------------------

[](#what-does-the-sync-script-do)

The sync script copies shared ruleset files from the package into the project root.

Currently applied files:

- `phpmd.xml`
- `phpcs.xml`
- `.php-cs-fixer.php`

### Overwrite behavior

[](#overwrite-behavior)

The sync process uses an always overwrite strategy:

- If rulesets already exist in the project root, they will be replaced
- This guarantees all projects use the exact same ruleset

This behavior is intentional and ensures consistency across projects. If you need to customize rules per project, fork this repository or manage overrides outside of this package.

---

Usage
-----

[](#usage)

After the sync script runs, the ruleset files will exist in your project root, but the corresponding tools must also be installed. However if you installed the package via `maarsson/dev-tools` you don’t need to install these manually. Otherwise run:

```
composer require --dev phpmd/phpmd
composer require --dev squizlabs/php_codesniffer
composer require --dev friendsofphp/php-cs-fixer
```

Note: `*.cache` should be added to `.gitignore`.

### Using PHPMD with the installed ruleset

[](#using-phpmd-with-the-installed-ruleset)

Run the PHPMD check for displaying violations like this:

`./vendor/bin/phpmd . ansi phpmd.xml --suffixes=php --cache --cache-file=.phpmd.cache`

### Using PHPCS with the installed ruleset

[](#using-phpcs-with-the-installed-ruleset)

Then run the PHPCS check for displaying violations like this:

`./vendor/bin/phpcs --parallel=4 --standard=phpcs.xml -d memory_limit=1G --cache=.phpcs.cache .`

Or run the PHPCBF (comes with the same package) to actually fix violations like this:

`./vendor/bin/phpcbf --parallel=4 --standard=phpcs.xml -d memory_limit=1G --cache=.phpcs.cache .`

### Using PHP-CS-Fixer with the installed ruleset

[](#using-php-cs-fixer-with-the-installed-ruleset)

Then run the PHP-CS-Fixer check for displaying violations like this:

`./vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php --cache-file=.php-cs-fixer.cache`

Or run the PHP-CS-Fixer to actually fix violations like this:

`./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --cache-file=.php-cs-fixer.cache`

---

Troubleshooting
---------------

[](#troubleshooting)

***Source file not found***

This typically means:

- the package is not installed correctly
- Composer install/update did not complete successfully

Try:

```
composer install
composer coding-standard:sync -vvv
```

***Sync script not executable***

Ensure your environment supports running scripts from vendor/bin and that file permissions are preserved.

---

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance76

Regular maintenance activity

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

9

Last Release

128d ago

PHP version history (2 changes)1.0.0PHP ^8.2

1.1.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/20db46ebf23900b28acd0afa60b864d8a247cf2d386aefc3493ea64631162c37?d=identicon)[maarsson](/maintainers/maarsson)

---

Top Contributors

[![maarsson](https://avatars.githubusercontent.com/u/43791389?v=4)](https://github.com/maarsson "maarsson (72 commits)")

---

Tags

standardsdevqa

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[symfony/contracts

A set of abstractions extracted out of the Symfony components

3.9k64.6M103](/packages/symfony-contracts)[symfony/translation-contracts

Generic abstractions related to translation

2.6k698.7M432](/packages/symfony-translation-contracts)[phpcompatibility/php-compatibility

A set of sniffs for PHP\_CodeSniffer that checks for PHP cross-version compatibility.

2.3k74.3M1.3k](/packages/phpcompatibility-php-compatibility)[automattic/vipwpcs

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

25510.2M145](/packages/automattic-vipwpcs)[wptrt/wpthemereview

PHP\_CodeSniffer rules (sniffs) to verify theme compliance with the rules for theme hosting on wordpress.org

217736.5k29](/packages/wptrt-wpthemereview)[orisai/coding-standard

Strict PHP coding standard

19193.5k62](/packages/orisai-coding-standard)

PHPackages © 2026

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