PHPackages                             voku/phpstan-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. voku/phpstan-rules

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

voku/phpstan-rules
==================

Provides additional rules for phpstan/phpstan.

3.7.0(2mo ago)3396.0k↓23.6%1[1 issues](https://github.com/voku/phpstan-rules/issues)[1 PRs](https://github.com/voku/phpstan-rules/pulls)5MITPHPPHP ^7.4 || ^8.0CI passing

Since Feb 17Pushed 2d ago2 watchersCompare

[ Source](https://github.com/voku/phpstan-rules)[ Packagist](https://packagist.org/packages/voku/phpstan-rules)[ Docs](https://github.com/voku/phpstan-rules)[ Fund](https://www.paypal.me/moelleken)[ GitHub Sponsors](https://github.com/voku)[ RSS](/packages/voku-phpstan-rules/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (6)Versions (56)Used By (5)

[![Build Status](https://github.com/voku/phpstan-rules/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/voku/phpstan-rules/actions)[![codecov.io](https://camo.githubusercontent.com/88653bef82b5b320342c4f66d9a8622ba6bb855e1be0517b2da100217f010bdd/68747470733a2f2f636f6465636f762e696f2f6769746875622f766f6b752f7068707374616e2d72756c65732f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/voku/phpstan-rules?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/6fcc8cd9af38e77693aae1bf60fb5dd3ef2d93d65fc5b4e6c1bb4f81e88fa7f7/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f7068707374616e2d72756c65732f762f737461626c65)](https://packagist.org/packages/voku/phpstan-rules)[![License](https://camo.githubusercontent.com/adb5b7a02378558abdb56dc9f0eb534b8ea1c2c23449c955bf473ae3334b84c1/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f7068707374616e2d72756c65732f6c6963656e7365)](https://packagist.org/packages/voku/phpstan-rules)[![Donate to this project using Paypal](https://camo.githubusercontent.com/0d6e4d8b50b5983a58205941b1a581b1305903393b7a39da574e3f60af3c7f5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e737667)](https://www.paypal.me/moelleken)[![Donate to this project using Patreon](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/voku)

phpstan-rules
=============

[](#phpstan-rules)

Provides additional rules for [`phpstan/phpstan`](https://github.com/phpstan/phpstan).

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

[](#installation)

Run

```
$ composer require --dev voku/phpstan-rules
```

Usage
-----

[](#usage)

All the [rules](https://github.com/voku/phpstan-rules#rules) provided (and used) by this library are included in [`rules.neon`](rules.neon).

When you are using [`phpstan/extension-installer`](https://github.com/phpstan/extension-installer), `rules.neon` will be automatically included.

Otherwise, you need to include `rules.neon` in your `phpstan.neon`:

```
includes:
	- vendor/voku/phpstan-rules/rules.neon
```

Rules
-----

[](#rules)

### IfConditionHelper

[](#ifconditionhelper)

This helper is used by different "condition"-rules: if - and - or - not - ternary

💡 We use this "hack" (helper) to run the check for all kind of conditions.

- double negative string conditions. e.g. `(string)$foo != ''` is the same as `(string)$foo`
    -
- double negative integer conditions. e.g. `(int)$foo != 0` is the same as `(int)$foo`
    -
- double negative boolean conditions. e.g. `(bool)$foo != false` is the same as `(bool)$foo`
    -
- double negative null conditions. Use "!==" instead if needed
    -
- check 0 vs '' conditions, the behavior was changed in PHP 8
    -
- check possible insane comparisons. e.g. `0 == '0foo'`, the behavior was changed in PHP 8
    -
- check insane comparisons. e.g. `0 === '0'` or `false && true`
- check non-empty string is never empty
- check non-empty string is always empty
- check non-empty array is never empty
- do not compare objects with another type
- do not use magic string-concat for objects with "\_\_toString()"
- do not allow assignments. e.g. `if ($a = 0)` (see "checkForAssignments")
- do not allow Yoda conditions. e.g. `ìf (0 == $a)` (see "checkYodaConditions")

#### Configuration

[](#configuration)

If you want to configure a list of classes / subclasses that can NOT be used in conditions directly:

e.g.:

- ok: `if ($emailValueObject->isValid())`
- error: `if ($emailValueObject != '')`

```
parameters:
    voku:
        classesNotInIfConditions: [
            AbstractValueObject
        ]
```

If you want to check assignments e.g. in "if"-conditions you can use this:

```
parameters:
    voku:
        checkForAssignments: true
```

If you want to check Yoda conditions can use this:

```
parameters:
    voku:
        checkYodaConditions: true
```

### ExtendedBinaryOpRule

[](#extendedbinaryoprule)

This rule will check "+", "\*", "/", "-", ... (operators) and "." (concatenation) for compatible types.

It's included in the default `rules.neon` so that you don't need to add it manually.

### DisallowedCallMethodOnNull

[](#disallowedcallmethodonnull)

This code is copy&amp;pasted from \[`phpstan/phpstan-src`\] and I used it to prevent `Call to a member function on null` errors while I wasn't already on level 8 where all kind of "NULL" checks are already covered by default.

e.g.

```
rules:
    - voku\PHPStan\Rules\DisallowedCallMethodOnNullRule
```

### Support

[](#support)

For support and donations please visit [Github](https://github.com/voku/phpstan-rules/) | [Issues](https://github.com/voku/phpstan-rules/issues) | [PayPal](https://paypal.me/moelleken) | [Patreon](https://www.patreon.com/voku).

For status updates and release announcements please visit [Releases](https://github.com/voku/phpstan-rules/releases) | [Twitter](https://twitter.com/suckup_de) | [Patreon](https://www.patreon.com/voku/posts).

For professional support please contact [me](https://about.me/voku).

### Thanks

[](#thanks)

- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to [Travis CI](https://travis-ci.com/) for being the most awesome, easiest continous integration tool out there!
- Thanks to [StyleCI](https://styleci.io/) for the simple but powerfull code style check.
- Thanks to [PHPStan](https://github.com/phpstan/phpstan) &amp;&amp; [Psalm](https://github.com/vimeo/psalm) for relly great Static analysis tools and for discover bugs in the code!

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance93

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 53.6% 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 ~38 days

Recently: every ~163 days

Total

41

Last Release

66d ago

Major Versions

1.10.0 → 2.0.02022-07-22

2.0.0 → 3.0.02022-07-29

PHP version history (2 changes)1.0.0PHP ^7.2 || ^8.0

3.6.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6456fe693db197c458272cb758bf78958bc7d3e787ccd59db4bf3cf41654316a?d=identicon)[voku](/maintainers/voku)

---

Top Contributors

[![voku](https://avatars.githubusercontent.com/u/264695?v=4)](https://github.com/voku "voku (97 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (40 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (28 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (8 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (7 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")

---

Tags

PHPStanphpstan-rulesphpstan-extreme-rules

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[larastan/larastan

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

6.5k55.4M8.4k](/packages/larastan-larastan)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

79475.7M2.2k](/packages/phpstan-phpstan-symfony)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

4853.5M91](/packages/shipmonk-dead-code-detector)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

67272.8M1.4k](/packages/phpstan-phpstan-doctrine)[sidz/phpstan-rules

Set of PHPStan rules

31507.9k21](/packages/sidz-phpstan-rules)[orrison/meliorstan

Provides PHPStan rules for improved code quality by detecting code smells and possible issues. In addition to enforcing particular naming and code style conventions to reduce bike-shedding.

1915.9k5](/packages/orrison-meliorstan)

PHPackages © 2026

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