GitHub - adaamz/thecodingmaching_phpstan-strict-rules: A set of additional rules for PHPStan based on best practices followed at TheCodingMachine · GitHub
Skip to content

adaamz/thecodingmaching_phpstan-strict-rules

 
 

Folders and files

Repository files navigation

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Build Status Coverage Status

TheCodingMachine's additional rules for PHPStan

This package contains a set of rules to be added to the wonderful PHPStan static analyzer.

Those rules come from TheCodingMachine best practices. They are more "strict" than the default PHPStan rules and some may be controversial. We use those at TheCodingMachine, have found them to help us in our daily work, and ask anyone working with us to follow them.

Rules list

Exception related rules

Type-hinting related rules

This is a PHP 7.1+ rule:

  • You should use type-hinting when possible
  • If not possible, you should use a Docblock to specify the type
  • If type-hinting against an array, you should use a Docblock to further explain the content of the array

More about type-hinting related rules...

Work-in-progress

// Don't use superglobals (__GET __POST)...
// Always provide a "default" in a switch statement (and throw an exception if unexpected)
// Never use public properties
// Force type hinting on all methods, starting with PHP 7.1 (or mixed must be passed in @param docblock to explain that we expect absolutely anything)

Installation

We assume that PHPStan is already installed in your project.

Let's add this package:

composer require --dev thecodingmachine/phpstan-strict-rules

Now, edit you phpstan.neon file and add these rules:

services:
  -
    class: TheCodingMachine\PHPStan\Rules\Exceptions\ThrowMustBundlePreviousExceptionRule
    tags:
      - phpstan.rules.rule
  -
    class: TheCodingMachine\PHPStan\Rules\Exceptions\DoNotThrowExceptionBaseClassRule
    tags:
      - phpstan.rules.rule
  -
    class: TheCodingMachine\PHPStan\Rules\Exceptions\EmptyExceptionRule
    tags:
      - phpstan.rules.rule
  -
    class: TheCodingMachine\PHPStan\Rules\TypeHints\MissingTypeHintInFunctionRule
    tags:
      - phpstan.rules.rule
  -
    class: TheCodingMachine\PHPStan\Rules\TypeHints\MissingTypeHintInMethodRule
    tags:
      - phpstan.rules.rule

About

A set of additional rules for PHPStan based on best practices followed at TheCodingMachine

Resources

Stars

Watchers

Forks

Packages

Contributors

Languages

  • PHP 100.0%