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

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

sidz/phpstan-rules
==================

Set of PHPStan rules

0.5.2(11mo ago)31507.9k—10%412MITPHPPHP ^8.1, &lt;8.6CI passing

Since Apr 10Pushed 11mo ago3 watchersCompare

[ Source](https://github.com/sidz/phpstan-rules)[ Packagist](https://packagist.org/packages/sidz/phpstan-rules)[ Docs](https://github.com/sidz/phpstan-rules)[ RSS](/packages/sidz-phpstan-rules/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (5)Versions (17)Used By (12)

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

[](#phpstan-rules)

[![Continuous Integration](https://github.com/sidz/phpstan-rules/workflows/Continuous%20Integration/badge.svg)](https://github.com/sidz/phpstan-rules/actions)

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

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

[](#installation)

Run

```
composer require --dev sidz/phpstan-rules
```

If you use [PHPStan extension installer](https://github.com/phpstan/extension-installer), you're all set. If not, you need to manually register all the rules in your `phpstan.neon`:

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

Each rule by default ignores the following numbers: `0` and `1`. This can be configured by adding the following parameter to your `phpstan.neon`:

```
parameters:
	sidzIgnoreMagicNumbers: [0, 1, 100]
```

Each rule by default detects numeric strings like `'12'` in source code. This behavior could be disabled via parameter:

```
parameters:
	sidzIgnoreNumericStrings: true
```

Ignoring particular rules
-------------------------

[](#ignoring-particular-rules)

If you need to ignore particular rule, for example `NoMagicNumberInComparisonOperatorRule`, you can do so by using built-in `ignoreErrors` parameter:

```
parameters:
    ignoreErrors:
        - '#^Do not use magic number in comparison operations\. Move to constant with a suitable name\.$#'
```

If you need to ignore this rule only for particular file or folder, this also can be done by using `ignoreErrors` parameter:

```
parameters:
    ignoreErrors:
        -
            message: '#^Do not use magic number in comparison operations\. Move to constant with a suitable name\.$#'
            path: src/SomeFolder/*
```

And finally, if you want to ignore all the rules from this package for particular files or folders, add this to `phpstan.neon`:

```
parameters:
    ignoreErrors:
        -
            message: '#Do not (use|return|assign) magic number (.)#'
            paths:
                - src/DataFixtures/*
                - tests/*
```

Rules
-----

[](#rules)

This package provides the following rules for use with [`phpstan/phpstan`](https://github.com/phpstan/phpstan):

- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberAsFunctionArgumentRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberasfunctionargumentrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberAssignedToPropertyRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberassignedtopropertyrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInArithmeticOperatorRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberinarithmeticoperatorrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInBitwiseOperatorRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberinbitwiseoperatorrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInComparisonOperatorRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberincomparisonoperatorrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInDefaultParameterRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberindefaultparameterrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInLogicalOperatorRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberinlogicaloperatorrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInMatchRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberinmatchrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInReturnStatementRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberinreturnstatementrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInSwitchCaseRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberinswitchcaserule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberInTernaryOperatorRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumberinternaryoperatorrule)
- [`Sid\PHPStan\Rules\MagicNumber\NoMagicNumberVariableAssignmentRule`](https://github.com/sidz/phpstan-rules#magicnumbernomagicnumbervariableassignmentrule)

### Classes

[](#classes)

#### `MagicNumber\NoMagicNumberAsFunctionArgumentRule`

[](#magicnumbernomagicnumberasfunctionargumentrule)

This rule reports an error when magic number is used as function argument:

```
