GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - thecodingmachine/phpstan-strict-rules: A set of additional rules for PHPStan based on best practices followed at TheCodingMachine

BranchesTags
Open more actions menu

Latest commit

 

History

104 Commits
104 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpstan-strict-rules.neon
phpstan-strict-rules.neon
 
 
phpstan.neon
phpstan.neon
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

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

  • You should not throw the "Exception" base class directly but throw a sub-class instead.
  • You should not have empty catch statements
  • When throwing an exception inside a catch block, you should pass the catched exception as the "previous" exception
  • If you catch a Throwable, an Exception or a RuntimeException, you must rethrow the exception.

Superglobal related rules

  • The use of $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_REQUEST is forbidden. You should instead use your framework's request/session object.
  • Superglobal usage is still tolerated at the root scope (because it is typically used once in index.php to initialize PSR-7 request object)

Condition related rules

  • Switch statements should always check for unexpected values by implementing a default case (and throwing an exception)

Work-in-progress

// Never use public properties
// Never use globals

Installation

We assume that PHPStan is already installed in your project.

To use this extension, require it in Composer:

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

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include phpstan-strict-rules.neon in your project's PHPStan config:

includes:
    - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon

About

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

Resources

Readme
Activity
Custom properties

Stars

287 stars

Watchers

17 watching

Forks

27 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.