shlinkio/php-coding-standard
This package is abandoned and no longer maintained.
The author suggests using the shlinkio/shlink-mago-config package instead.
Coding standard used by shlink PHP projects
Maintainers
Package info
github.com/shlinkio/php-coding-standard
Language:Shell
Type:phpcodesniffer-standard
pkg:composer/shlinkio/php-coding-standard
v2.5.0
2025-10-06 06:44 UTC
Requires
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Note
This project is no longer supported, since all Shlink PHP projects are now linted and formatted with Mago.
This repository provides a PHP_CodeSniffer ruleset with the rules used by shlink PHP projects.
Usage
First, install this package using composer:
composer require shlinkio/php-coding-standard --dev
Then, update your phpcs.xml file, adding a rule with the reference to Shlinkio.
<?xml version="1.0"?> <ruleset name="Coding standard"> <description>Coding standard</description> <!-- display progress --> <arg value="p" /> <arg name="colors" /> <!-- inherit rules from: --> <rule ref="Shlinkio" /> <!-- [...] --> </ruleset>
Rules
This ruleset extends PSR-12 rules, and includes:
- Do not allow array long syntax [
array(...)]. - Make sure string concatenation operator is surrounded by spaces.
- Do not allow superfluous whitespaces.
- Do not allow unused use statements.
- Require alphabetically ordered use statements.
- Require strict comparisons (
===and!==instead of==and!=). - Require trailing comma on every element of multi-line arrays.
- Require trailing comma on every element of multi-line function calls.
- Require trailing comma on every element of multi-line function declarations.
- Enforce all global namespace classes, functions and constants to be explicitly imported.
- Require comments with single line written as one-liners [
/* @var SomeType **/]. - Make all class constants to have a visibility modifier (
public,protectedorprivate). - Require function arguments with a default
nullvalue to be defined as nullable (?string $foo = 'foo'). - Require function arguments to have a native type hint whenever possible.
- Require functions to have a native return type hint whenever possible.
- Require properties to have a native type hint whenever possible.
- Require non-capturing catch when the exception variable is not used.
- Format union types without spaces (
foo|bar) and enforcing null at the end for nullables (foo|bar|null).
