Skip to content

Coding standard used by shlink PHP projects

License

Notifications You must be signed in to change notification settings

acelaya-forks/php-coding-standard

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shlink coding standard

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, protected or private).
  • Require function arguments with a default null value 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).

About

Coding standard used by shlink PHP projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%