talira

Slevomat Coding Standard

Extra PHP_CodeSniffer sniffs for safer, cleaner and consistently formatted PHP

open sourceMITfree

Slevomat Coding Standard is an open source set of sniffs for PHP_CodeSniffer, made by Slevomat.cz. Its sniffs fall into three groups: functional ones that make code safer and behave better, cleaning ones that find dead code, and formatting ones for a consistent look. Many of them fix their errors automatically with phpcbf, and some can be suppressed locally. You pick the sniffs you want or exclude ones you don't in your ruleset.

Problems it solves

  • enforce strict types and catch unused code in a PHP project with phpcs
  • add more PHP_CodeSniffer rules than PSR-12 gives me
  • automatically fix PHP code style issues in CI

Features

  • functional sniffs that improve code safety and behaviour
  • cleaning sniffs that detect dead code
  • formatting sniffs for consistent code style
  • automatic fixing for many sniffs
  • local suppression of sniff checks

Limitations

  • Sniffs expect syntactically valid code and can behave unexpectedly on files with parse errors; its makers advise running PHP Parallel Lint first.1

Alternatives

The same job

These do what Slevomat Coding Standard does.

  1. PHP_CodeSniffer Detect and fix coding standard violations in PHP
  2. laminas-coding-standard The Laminas Project's PHP_CodeSniffer coding standard ruleset, built on PSR-12
  3. Easy Coding Standard (ECS) Runs PHP_CodeSniffer and PHP-CS-Fixer rules together, fast
  4. WordPress Coding Standards for PHP_CodeSniffer PHP_CodeSniffer rules that enforce WordPress coding conventions
  5. PHP_CodeSniffer Standards Composer Installer Plugin Composer plugin that registers installed PHP_CodeSniffer coding standards automatically
  6. PHPMD PHP Mess Detector: finds bugs and code smells in PHP

Compare Slevomat Coding Standard with the top 3