PHPackages                             kcs/phpstan-strict-rules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. kcs/phpstan-strict-rules

ActivePhpstan-extension[Testing &amp; Quality](/categories/testing)

kcs/phpstan-strict-rules
========================

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

v2.1.0(7mo ago)324.0k↓16.4%MITPHPPHP ^7.4 || ^8.0CI passing

Since Jun 27Pushed 7mo agoCompare

[ Source](https://github.com/alekitto/phpstan-strict-rules)[ Packagist](https://packagist.org/packages/kcs/phpstan-strict-rules)[ RSS](/packages/kcs-phpstan-strict-rules/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (33)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/d7eedc53bd1639345dbd9e71f46b138f38b0163cbb74e8d520846e19f55d9ad8/68747470733a2f2f706f7365722e707567782e6f72672f6b63732f7068707374616e2d7374726963742d72756c65732f762f737461626c65)](https://packagist.org/packages/kcs/phpstan-strict-rules)[![Total Downloads](https://camo.githubusercontent.com/63f748180f60c5709ec9f53ac030e7c19a74748b9acf035b46bb79024818db96/68747470733a2f2f706f7365722e707567782e6f72672f6b63732f7068707374616e2d7374726963742d72756c65732f646f776e6c6f616473)](https://packagist.org/packages/kcs/phpstan-strict-rules)[![Latest Unstable Version](https://camo.githubusercontent.com/d7af8c4bc58e950ddb73298eea98dcc30102fbe9a342f90f99a8ee9c4eb830bc/68747470733a2f2f706f7365722e707567782e6f72672f6b63732f7068707374616e2d7374726963742d72756c65732f762f756e737461626c65)](https://packagist.org/packages/kcs/phpstan-strict-rules)[![License](https://camo.githubusercontent.com/4d4237a8a9eb139b6362a26354913ff26901fced1f16f96607be6fc1f39807d5/68747470733a2f2f706f7365722e707567782e6f72672f6b63732f7068707374616e2d7374726963742d72756c65732f6c6963656e7365)](https://packagist.org/packages/kcs/phpstan-strict-rules)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/14deb37a4145989e2711eb7643c81a104969120360103495d7778b67bb00bbc0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b63732f7068707374616e2d7374726963742d72756c65732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/kcs/phpstan-strict-rules/?branch=master)[![Build Status](https://camo.githubusercontent.com/3dae1d01a7760d3992939d94886001f2fcfd29ac9a57bc587908390cd96db612/68747470733a2f2f7472617669732d63692e6f72672f6b63732f7068707374616e2d7374726963742d72756c65732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kcs/phpstan-strict-rules)[![Coverage Status](https://camo.githubusercontent.com/d7dc0f4672b211019db87c9428f114389226ada4b9759e9ebb22e87a7e982146/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b63732f7068707374616e2d7374726963742d72756c65732f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/kcs/phpstan-strict-rules?branch=master)

This is a fork of the popular `thecodingmachine/phpstan-strict-rules`
---------------------------------------------------------------------

[](#this-is-a-fork-of-the-popular-thecodingmachinephpstan-strict-rules)

To push forward the development of this package and the adoption of phpstan v2, this package has been forked, as the original repository seems semi-abandoned. Versioning starts from 2.0 and retains all the features of the original package. Namespace has not been changed.

Once the original project restarts, it is possible that this package would be abandoned. In case the original package is left abandoned for a longer time, this will be a hard fork, with different namespaces and so on...

TheCodingMachine's additional rules for PHPStan
===============================================

[](#thecodingmachines-additional-rules-for-phpstan)

This package contains a set of rules to be added to the [wonderful PHPStan static analyzer](https://phpstan.org/).

Those rules come from [TheCodingMachine best practices](http://bestpractices.thecodingmachine.com/). 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
----------

[](#rules-list)

### Exception related rules

[](#exception-related-rules)

- You should not throw the "Exception" base class directly [but throw a sub-class instead](http://bestpractices.thecodingmachine.com/php/error_handling.html#subtyping-exceptions).
- 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](http://bestpractices.thecodingmachine.com/php/error_handling.html#wrapping-an-exception-do-not-lose-the-previous-exception)
- If you catch a `Throwable`, an `Exception` or a `RuntimeException`, you must rethrow the exception.

### Superglobal related rules

[](#superglobal-related-rules)

- The use of [`$_GET`, `$_POST`, `$_FILES`, `$_COOKIE`, `$_SESSION`, `$_REQUEST` is forbidden](http://bestpractices.thecodingmachine.com/php/organize_your_code.html#stop-using-superglobals-). 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

[](#condition-related-rules)

- Switch statements should always check for unexpected values by [implementing a default case (and throwing an exception)](http://bestpractices.thecodingmachine.com/php/defensive_programming.html#always-check-for-unexpected-values)

### Work-in-progress

[](#work-in-progress)

```
// Never use public properties
// Never use globals

```

Installation
------------

[](#installation)

We assume that [PHPStan](https://phpstan.org/) is already installed in your project.

To use this extension, require it in [Composer](https://getcomposer.org/):

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

If you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!

 Manual installationIf 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
```

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance62

Regular maintenance activity

Popularity32

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 81.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Recently: every ~461 days

Total

31

Last Release

233d ago

Major Versions

v0.12.2 → v1.0.02021-11-08

v1.0.0 → v2.0.02025-03-13

PHP version history (4 changes)0.7.0PHP &gt;=7.1

v0.10.0PHP ^7.1

v0.12.1PHP ^7.1|^8.0

v2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/73dd7f3bebd03ec946b6b12359141ea461b770c3671acac4e8004e3c2d78e78f?d=identicon)[alekitto](/maintainers/alekitto)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (89 commits)")[![alekitto](https://avatars.githubusercontent.com/u/1257206?v=4)](https://github.com/alekitto "alekitto (10 commits)")[![adaamz](https://avatars.githubusercontent.com/u/4347332?v=4)](https://github.com/adaamz "adaamz (2 commits)")[![dongm2ez](https://avatars.githubusercontent.com/u/9032795?v=4)](https://github.com/dongm2ez "dongm2ez (1 commits)")[![marcinharasim](https://avatars.githubusercontent.com/u/16610387?v=4)](https://github.com/marcinharasim "marcinharasim (1 commits)")[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (1 commits)")[![ondrejmirtes](https://avatars.githubusercontent.com/u/104888?v=4)](https://github.com/ondrejmirtes "ondrejmirtes (1 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (1 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (1 commits)")[![adrienbrault](https://avatars.githubusercontent.com/u/611271?v=4)](https://github.com/adrienbrault "adrienbrault (1 commits)")[![alexander-schranz](https://avatars.githubusercontent.com/u/1698337?v=4)](https://github.com/alexander-schranz "alexander-schranz (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kcs-phpstan-strict-rules/health.svg)

```
[![Health](https://phpackages.com/badges/kcs-phpstan-strict-rules/health.svg)](https://phpackages.com/packages/kcs-phpstan-strict-rules)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

78768.9M1.5k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

66766.6M1.1k](/packages/phpstan-phpstan-doctrine)[phpat/phpat

PHP Architecture Tester

1.2k3.5M32](/packages/phpat-phpat)[spaze/phpstan-disallowed-calls

PHPStan rules to detect disallowed method &amp; function calls, constant, namespace, attribute, property &amp; superglobal usages, with powerful rules to re-allow a call or a usage in places where it should be allowed.

33320.0M375](/packages/spaze-phpstan-disallowed-calls)[mglaman/phpstan-drupal

Drupal extension and rules for PHPStan

20829.0M124](/packages/mglaman-phpstan-drupal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
