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

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

magician79/coding-standard
==========================

Shared coding standards: PHPCS (PSR-12 + Slevomat) and PHPStan defaults for PHP8 projects.

v2.0.1(8mo ago)0831MITPHP &gt;=8.1CI passing

Since Sep 5Pushed 8mo agoCompare

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

READMEChangelogDependencies (8)Versions (5)Used By (1)

Magician79 Coding Standard
==========================

[](#magician79-coding-standard)

[![CI](https://github.com/magician79/coding-standard/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/magician79/coding-standard/actions/workflows/ci.yml)

Shared coding standards for PHP projects:

- **PHPCS** — Doctrine Coding Standard (PSR-12 + curated Slevomat) as a baseline, with Pragmatic and Strict profiles
- **PHPStan** — Pragmatic and Strict configs
- **Syntax linting** — via php-parallel-lint (with optional var-dump check)

Packaged for easy reuse across repositories with sensible defaults and stricter opt-ins.

---

Table of Contents
-----------------

[](#table-of-contents)

- [What this package provides](#what-this-package-provides)
- [Installation](#installation)
- [PHPCS ruleset profiles](#phpcs-ruleset-profiles)
- [PHPStan profiles](#phpstan-profiles)
- [PHP syntax linting](#php-syntax-linting-php-parallel-lint)
- [Quick usage options](#quick-usage-options)
- [Choosing a PHPCS profile](#choosing-a-phpcs-profile)
- [Excluding or tuning sniffs](#excluding-or-tuning-sniffs)
- [PHPStan: extend in a project](#phpstan-extend-in-a-project-recommended-for-larger-repos)
- [Composer and installation behavior](#composer-and-installation-behavior-faq)
- [CI examples](#ci-examples-consumer-project)
- [Pre-commit hook example](#pre-commit-hook-example-consumer-project)
- [Versioning and upgrade policy](#versioning-and-upgrade-policy)
- [Troubleshooting](#troubleshooting)
- [License](#license)

---

What this package provides
--------------------------

[](#what-this-package-provides)

- **PHPCS rulesets**

    - *Pragmatic* (default): Based on Doctrine coding standard, this profile balances strictness with low noise and high autofix coverage. It avoids overlapping or conflicting PHPCS sniffs by carefully selecting compatible rules.
    - *Strict* (opt-in): Extends the Pragmatic profile with a stricter set of sniffs from Doctrine and Slevomat for maximum code quality and rigor, suitable for new or greenfield modules.
- **PHPStan configurations**

    - *Pragmatic* (default): Level 6 + noise reduction toggles.
    - *Strict* (opt-in): Level max, bleedingEdge, phpstan-strict-rules included.
- **PHP syntax linting**

    - `php-parallel-lint` (fast, parallel parse error detection)
    - Optional `var-dump-check` to block accidental debug prints.
- **Optional Composer scripts**

    - Predefined tasks (`cs`, `stan`, `check`, etc.) for quick setup.
- **Out-of-the-box tooling**

    - PHPCS, Doctrine Coding Standard, Slevomat, PHPStan, php-parallel-lint are bundled so consumers don’t need to install them separately.

---

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

[](#installation)

Install in your project as a dev dependency:

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

This installs (into your project’s `vendor/`):

- `doctrine/coding-standard`
- `squizlabs/php_codesniffer`
- `slevomat/coding-standard`
- `dealerdirect/phpcodesniffer-composer-installer`
- `phpstan/phpstan` (+ `phpstan/phpstan-strict-rules`)
- `php-parallel-lint/php-parallel-lint`
- (optional) `php-parallel-lint/php-var-dump-check`, `php-parallel-lint/php-console-highlighter`

Note: tools are installed in dev mode (`composer install`). They are omitted in production installs (`composer install --no-dev`).

---

PHPCS ruleset profiles
----------------------

[](#phpcs-ruleset-profiles)

There are two PHPCS profiles in this package:

- **Pragmatic profile (recommended default)**

    - File: `vendor/magician79/coding-standard/ruleset/phpcs.pragmatic.xml`
    - Intent: Low-friction adoption. Doctrine baseline + curated Slevomat. Enforces `declare(strict_types=1)`, type hints, imports hygiene, strict comparisons, unused code cleanup, and a pragmatic line length rule. Most findings are auto-fixable via `phpcbf`.
- **Strict profile (opt-in)**

    - File: `vendor/magician79/coding-standard/ruleset/phpcs.strict.xml`
    - Intent: Maximum rigor by extending the Doctrine baseline and Pragmatic profile with nearly all Slevomat sniffs. Best for new projects or modules. Expect to exclude or tune some sniffs.

---

PHPStan profiles
----------------

[](#phpstan-profiles)

This package ships two PHPStan configurations:

- **Pragmatic (default)**

    - File: `vendor/magician79/coding-standard/phpstan/pragmatic.neon.dist`
    - Level 6 with noise-reducing toggles. Designed for adoption on existing code.
- **Strict (opt-in)**

    - File: `vendor/magician79/coding-standard/phpstan/strict.neon.dist`
    - Level max, phpstan-strict-rules included. Ideal for greenfield modules.

Run directly:

```
# Pragmatic
vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/pragmatic.neon.dist

# Strict
vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/strict.neon.dist
```

---

PHP syntax linting (php-parallel-lint)
--------------------------------------

[](#php-syntax-linting-php-parallel-lint)

`php-parallel-lint` runs a fast, parallel parse check of your PHP files. It catches syntax/parse errors before PHPCS or PHPStan run.

Useful flags:

- `-j 8` or higher for concurrency
- `--colors` for readable output
- `--exclude` to skip vendor/cache/build directories
- `--blame` to show the author of the failing line

Run directly:

```
# Basic syntax check (fast fail)
vendor/bin/parallel-lint --colors -j 8 --exclude vendor --exclude var --exclude storage --exclude cache --exclude .git .
```

Optional: disallow debug prints using `php-var-dump-check`:

```
vendor/bin/var-dump-check --skip-dir=vendor --skip-dir=var --skip-dir=storage --skip-dir=cache .
```

---

Quick usage options
-------------------

[](#quick-usage-options)

### Option A: Use shared profiles via Composer scripts

[](#option-a-use-shared-profiles-via-composer-scripts)

Add to your project’s `composer.json`:

```
{
  "scripts": {
    "lint:php": "parallel-lint --colors -j 8 --exclude vendor --exclude var --exclude storage --exclude cache --exclude .git .",
    "lint:debug": "var-dump-check --skip-dir=vendor --skip-dir=var --skip-dir=storage --skip-dir=cache .",

    "cs": "sh -c 'if [ -f phpcs.xml ]; then vendor/bin/phpcs -p --standard=phpcs.xml; else vendor/bin/phpcs --standard=vendor/magician79/coding-standard/ruleset/phpcs.pragmatic.xml; fi'",
    "cs:strict": "sh -c 'if [ -f phpcs.xml ]; then vendor/bin/phpcs -p --standard=phpcs.xml; else vendor/bin/phpcs --standard=vendor/magician79/coding-standard/ruleset/phpcs.strict.xml; fi'",
    "fix": "sh -c 'if [ -f phpcs.xml ]; then vendor/bin/phpcbf --standard=phpcs.xml; else vendor/bin/phpcbf --standard=vendor/magician79/coding-standard/ruleset/phpcs.pragmatic.xml; fi'",
    "fix:strict": "sh -c 'if [ -f phpcs.xml ]; then vendor/bin/phpcbf --standard=phpcs.xml; else vendor/bin/phpcbf --standard=vendor/magician79/coding-standard/ruleset/phpcs.strict.xml; fi'",

    "stan": "sh -c 'if [ -f phpstan.neon.dist ]; then vendor/bin/phpstan analyse -c phpstan.neon.dist; else vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/pragmatic.neon.dist; fi'",
    "stan:strict": "sh -c 'if [ -f phpstan.neon.dist ]; then vendor/bin/phpstan analyse -c phpstan.neon.dist; else vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/strict.neon.dist; fi'",

    "check": [
      "@lint:php",
      "@cs",
      "@stan"
    ],
    "check:strict": [
      "@lint:php",
      "@cs:strict",
      "@stan:strict"
    ]
  }
}
```

Run:

- `composer lint:php`
- `composer cs`
- `composer fix`
- `composer stan`
- `composer check` (syntax lint → PHPCS → PHPStan)

#### Option B: Extend rules in your project (recommended for larger projects)

[](#option-b-extend-rules-in-your-project-recommended-for-larger-projects)

Create `phpcs.xml` in your project root:

```

  src
  app
  config
  tests
  vendor/*
  var/*
  generated/*

```

Run:

- `vendor/bin/phpcs`
- `vendor/bin/phpcbf`

---

Choosing a PHPCS profile
------------------------

[](#choosing-a-phpcs-profile)

- **Pragmatic**: best for existing/legacy code.
- **Strict**: best for new projects or modernized code.

You can also mix: Pragmatic globally, Strict on certain paths:

```
src/NewModule

  src/NewModule/*

```

---

Excluding or tuning sniffs
--------------------------

[](#excluding-or-tuning-sniffs)

You can always exclude or adjust any sniff in your project’s `phpcs.xml`:

- Disable globally:

    ```

    ```
- Demote error to warning:

    ```

    ```
- Exclude by path:

    ```
    src/Legacy/*
    ```

---

PHPStan: extend in a project (recommended for larger repos)
-----------------------------------------------------------

[](#phpstan-extend-in-a-project-recommended-for-larger-repos)

Create a `phpstan.neon.dist` file in your project root and include one of the shared profiles.

Pragmatic baseline:

```
includes:
  - vendor/magician79/coding-standard/phpstan/pragmatic.neon.dist

parameters:
  level: 7
  paths:
    - src
    - tests
  parallel:
    maximumNumberOfProcesses: 6

# Optionally include a project-specific baseline
# includes:
#   - phpstan-baseline.neon
```

Or Strict mode:

```
includes:
  - vendor/magician79/coding-standard/phpstan/strict.neon.dist

parameters:
  paths:
    - src
    - tests

# Optional extensions (install in your project first):
# includes:
#   - vendor/phpstan/phpstan-doctrine/extension.neon
#   - vendor/phpstan/phpstan-phpunit/extension.neon
```

Baselines:

- This package does not ship a baseline. Generate one in your project only if needed:
    - `vendor/bin/phpstan analyse --generate-baseline=phpstan-baseline.neon`
- Consider starting with Pragmatic without a baseline; use Strict for new modules or as a second CI job.

Mix-and-match:

- Use Pragmatic globally and enforce Strict on certain paths (e.g., `src/NewModule`) by running a second job or restricting analysis paths:

```
vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/strict.neon.dist src/NewModule
```

Performance tips:

- Parallel analysis is enabled by default; tweak `maximumNumberOfProcesses` per project.
- Limit paths for faster iteration during refactors.
- Ensure `var/cache/phpstan` is writable in your environment.

---

Composer and installation behavior (FAQ)
----------------------------------------

[](#composer-and-installation-behavior-faq)

- Add under `require-dev` in consumer projects.
- In dev installs, all tools are present.
- In production (`--no-dev`), the package is omitted and none of the tooling is present.
- Rule of thumb:
    - Shared package: put tools in `require` so they’re available whenever the consumer installs your package as a dev dependency.
    - Consumer project: add `magician79/coding-standard` under `require-dev`.

---

CI examples (consumer project)
------------------------------

[](#ci-examples-consumer-project)

Run php-parallel-lint first to fail fast, then PHPCS and PHPStan. This workflow uses local config if present, otherwise falls back to vendor defaults.

Minimal pragmatic job:

```
name: Code Quality

on: [push, pull_request]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
          tools: composer:v2
          coverage: none
      - run: composer install --no-interaction --prefer-dist

      - name: PHP syntax lint (fast fail)
        run: vendor/bin/parallel-lint --colors -j 8 --exclude vendor --exclude var --exclude storage --exclude cache --exclude .git .

      - name: PHPCS (Pragmatic, local override if exists)
        run: |
          if [ -f phpcs.xml ]; then
            vendor/bin/phpcs -p --standard=phpcs.xml
          else
            vendor/bin/phpcs -p --standard=vendor/magician79/coding-standard/ruleset/phpcs.pragmatic.xml --ignore=vendor/* -q .
          fi

      - name: PHPStan (Pragmatic, local override if exists)
        run: |
          if [ -f phpstan.neon.dist ]; then
            vendor/bin/phpstan analyse -c phpstan.neon.dist --no-progress
          else
            vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/pragmatic.neon.dist --no-progress .
          fi
```

Separate jobs for strict profiles:

```
jobs:
  rule-pragmatic:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
          tools: composer:v2
      - run: composer install --no-interaction --prefer-dist
      - run: vendor/bin/parallel-lint --colors -j 8 --exclude vendor --exclude var --exclude storage --exclude cache --exclude .git .

      - name: PHPCS (Pragmatic, local override if exists)
        run: |
          if [ -f phpcs.xml ]; then
            vendor/bin/phpcs -p --standard=phpcs.xml
          else
            vendor/bin/phpcs -p --standard=vendor/magician79/coding-standard/ruleset/phpcs.pragmatic.xml --ignore=vendor/* -q .
          fi

      - name: PHPStan (Pragmatic, local override if exists)
        run: |
          if [ -f phpstan.neon.dist ]; then
            vendor/bin/phpstan analyse -c phpstan.neon.dist --no-progress
          else
            vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/pragmatic.neon.dist --no-progress .
          fi

  rule-strict:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
          tools: composer:v2
      - run: composer install --no-interaction --prefer-dist
      - run: vendor/bin/parallel-lint --colors -j 8 --exclude vendor --exclude var --exclude storage --exclude cache --exclude .git .

      - name: PHPCS (Strict, local override if exists)
        run: |
          if [ -f phpcs.xml ]; then
            vendor/bin/phpcs -p --standard=phpcs.xml
          else
            vendor/bin/phpcs -p --standard=vendor/magician79/coding-standard/ruleset/phpcs.strict.xml --ignore=vendor/* -q .
          fi

      - name: PHPStan (Strict, local override if exists)
        run: |
          if [ -f phpstan.neon.dist ]; then
            vendor/bin/phpstan analyse -c phpstan.neon.dist --no-progress
          else
            vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/strict.neon.dist --no-progress .
          fi
      # Optionally scope strict to a directory:
      # - run: vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/strict.neon.dist src/NewModule
```

---

Pre-commit hook example (consumer project)
------------------------------------------

[](#pre-commit-hook-example-consumer-project)

Create `.git/hooks/pre-commit`:

```
#!/bin/sh
vendor/bin/parallel-lint -j 8 --exclude vendor --exclude var --exclude storage --exclude cache --exclude .git . || exit 1

if [ -f phpcs.xml ]; then
  vendor/bin/phpcs --standard=phpcs.xml || exit 1
else
  vendor/bin/phpcs --standard=vendor/magician79/coding-standard/ruleset/phpcs.pragmatic.xml --ignore=vendor/* -q . || exit 1
fi

if [ -f phpstan.neon.dist ]; then
  vendor/bin/phpstan analyse -c phpstan.neon.dist || exit 1
else
  vendor/bin/phpstan analyse -c vendor/magician79/coding-standard/phpstan/pragmatic.neon.dist . || exit 1
fi
```

Make it executable:

```
chmod +x .git/hooks/pre-commit
```

---

Versioning and upgrade policy
-----------------------------

[](#versioning-and-upgrade-policy)

- SemVer:
    - MAJOR: enabling stricter default rules or changing defaults in a way that could fail existing code.
    - MINOR: new profiles, optional rules, docs, examples that don’t change defaults.
    - PATCH: bug fixes and small non-breaking updates.
- Consumers can pin the package version in `composer.json` and choose when to upgrade.
- As of v2.0.0, the Pragmatic and Strict PHPCS profiles are based on the Doctrine Coding Standard with curated Slevomat rules. This reduces overlaps and conflicts. External usage (filenames, commands) remains unchanged. Consumers should re-check their codebase when upgrading to v2.x.

---

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

[](#troubleshooting)

- **PHPCS can’t find Slevomat rules**: ensure `dealerdirect/phpcodesniffer-composer-installer` is installed (brought by this package). Run `composer dump-autoload` if needed.
- **Too many findings initially**: start with Pragmatic; run `phpcbf` to auto-fix; then suppress or exclude remaining sniffs that don’t fit your context.
- **PHPStan seems slow**: enable `parallel` in your project config and scope paths to `src` and `tests`.
- **php-parallel-lint finds errors your PHP version accepts**: remember it validates against the PHP version it runs under. In CI, use a matrix or the production PHP version to ensure compatibility.

---

License
-------

[](#license)

MIT. See LICENSE in this repository.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance61

Regular maintenance activity

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

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

Total

4

Last Release

247d ago

Major Versions

v1.0.1 → v2.0.02025-09-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/da87d31ee69fc481a8a9536ca326fefd46eab45b3b84d34247834f6a62468e0b?d=identicon)[magician79](/maintainers/magician79)

---

Top Contributors

[![magician79](https://avatars.githubusercontent.com/u/9150976?v=4)](https://github.com/magician79 "magician79 (19 commits)")

---

Tags

phpcsPHPStanCoding Standardpsr-12slevomat

### Embed Badge

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

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

###  Alternatives

[wp-cli/wp-cli-tests

WP-CLI testing framework

422.7M87](/packages/wp-cli-wp-cli-tests)[yoast/yoastcs

PHP\_CodeSniffer rules for Yoast projects

221.1M29](/packages/yoast-yoastcs)[mayflower/mo4-coding-standard

PHP CodeSniffer ruleset implementing the MO4 coding standards extending the Symfony coding standards.

17508.3k5](/packages/mayflower-mo4-coding-standard)[orisai/coding-standard

Strict PHP coding standard

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

Webimpress Coding Standard

142.1M37](/packages/webimpress-coding-standard)[youwe/testing-suite

Contains Youwe's default testing packages for php.

13176.9k8](/packages/youwe-testing-suite)

PHPackages © 2026

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