Repolode
slevomat

slevomat/coding-standard

A set of PHP_CodeSniffer sniffs enforcing safer, cleaner and consistently formatted PHP code, many with automatic fixing.

Stars
1,477
Forks
197
Open issues
93
Last commit
21 hours ago

What is it?

Slevomat Coding Standard is a rule set for PHP_CodeSniffer, the tool that checks PHP source code against a coding standard. It bundles a large number of individual sniffs grouped into three areas: functional rules that improve safety and behaviour, cleanup rules that detect dead code, and formatting rules that keep code looking consistent.

Many sniffs cover modern PHP features such as attributes, enums, union types, named arguments and constructor property promotion. Sniffs marked as fixable can be applied automatically with phpcbf, and some sniffs can be suppressed locally with a @phpcsSuppress annotation when a project needs an exception.

The standard is installed through Composer as a dev dependency. Projects can reference only the sniffs they want in their own ruleset.xml, which is the recommended approach, or include the full ruleset and exclude specific sniffs.

Key features

  • 01Covers arrays, classes, control structures, functions, namespaces, type hints and more.
  • 02Many sniffs can automatically fix violations via phpcbf.
  • 03Detects dead code such as unused variables, parameters and imports.
  • 04Supports modern PHP syntax including attributes, enums and union types.
  • 05Lets projects select individual sniffs or exclude specific ones.

Use cases

  • Enforcing a consistent PHP code style across a team's project.
  • Catching unused code and risky constructs during continuous integration.
  • Automatically cleaning up legacy PHP codebases with phpcbf.
  • Building a custom PHP coding standard from a curated set of sniffs.

Quick start

  1. 1

    Install the standard with Composer as a dev dependency

    composer require --dev slevomat/coding-standard
  2. 2

    Configure PHP_CodeSniffer to use the standard and run it on your code

Things to know

  • Requires PHP_CodeSniffer as a dependency, so you need a PHP and Composer setup.

In collections

Topics

#php#code-style#linting#phpcs#static-analysis#coding-standard#php7#php8#phpcodesniffer

FAQ

What is coding-standard?
A set of PHP_CodeSniffer sniffs enforcing safer, cleaner and consistently formatted PHP code, many with automatic fixing. Slevomat Coding Standard is a rule set for PHP_CodeSniffer, the tool that checks PHP source code against a coding standard. It bundles a large number of individual sniffs grouped into three areas: functional rules that improve safety and behaviour, cleanup rules that detect dead code, and formatting rules that keep code looking consistent.
Is coding-standard free to use? What license does it have?
coding-standard is open source under the MIT license. Check the license terms before using it in commercial products.
Is coding-standard still maintained?
Actively maintained. The last commit to coding-standard was on Nov 5, 2026.
What can I use coding-standard for?
Enforcing a consistent PHP code style across a team's project. Catching unused code and risky constructs during continuous integration. Automatically cleaning up legacy PHP codebases with phpcbf. Building a custom PHP coding standard from a curated set of sniffs.
How do I install coding-standard?
Install the standard with Composer as a dev dependency: composer require --dev slevomat/coding-standard Configure PHP_CodeSniffer to use the standard and run it on your code
Where can I get coding-standard?
The source code and installation instructions are on GitHub: https://github.com/slevomat/coding-standard

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects