PHPackages                             martinsoenen/phpstan-custom-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. martinsoenen/phpstan-custom-rules

ActivePhpstan-extension[Validation &amp; Sanitization](/categories/validation)

martinsoenen/phpstan-custom-rules
=================================

Some custom PHPStan extensions for a better code base

v0.2.1(9mo ago)0933MITPHPPHP &gt;=7.4CI passing

Since Jul 17Pushed 9mo agoCompare

[ Source](https://github.com/martinsoenen/phpstan-custom-rules)[ Packagist](https://packagist.org/packages/martinsoenen/phpstan-custom-rules)[ RSS](/packages/martinsoenen-phpstan-custom-rules/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

PHPStan Custom Rules
====================

[](#phpstan-custom-rules)

[![CI state](https://camo.githubusercontent.com/204be70096cf1380161a3656187cf21b8026817e2e28d822b25940f7ac08e947/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d617274696e736f656e656e2f7068707374616e2d637573746f6d2d72756c65732f74657374732e796d6c)](https://github.com/martinsoenen/phpstan-custom-rules)[![Packagist version](https://camo.githubusercontent.com/e6bd1ecc2a3110e8f1e11cccfd8dd851b8b2c98a1cd33e589eea6dd2cba513d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617274696e736f656e656e2f7068707374616e2d637573746f6d2d72756c6573)](https://packagist.org/packages/martinsoenen/phpstan-custom-rules)

> Some custom PHPStan extensions to improve the readability, maintainability and overall quality of your PHP code base.

Package based on PHPStan. You can find the source package [here](https://phpstan.org/).

### Supported PHP versions

[](#supported-php-versions)

PHP versionThis package version7.4, 8.xLatestHow to use it
-------------

[](#how-to-use-it)

**1**: First, you may use [Composer](https://getcomposer.org) to install this package as a development dependency into your project:

```
composer require --dev "martinsoenen/phpstan-custom-rules"
```

**2**: Then, create a `phpstan.neon` or `phpstan.neon.dist` file in the root of your application. It might look like this:

```
includes:
    - vendor/martinsoenen/phpstan-custom-rules/extension.neon

parameters:
    paths:
        - src/

    # 0 to 10, level 10 is the highest level
    level: 0

```

The most important part is the `includes` one, that enables the rules of this package.

For all available options, please take a look at the PHPStan documentation: ****

**3**: Finally, you may start analyzing your code using the phpstan console command:

```
./vendor/bin/phpstan
```

Rules
-----

[](#rules)

### Boolean Property Naming Rule

[](#boolean-property-naming-rule)

*Identifier : martinsoenen.booleanPropertyNaming*

Ensure that a Boolean is always named with an “is” at the beginning of its name, to clarify the condition it represents.

### Max Line Per Class Rule

[](#max-line-per-class-rule)

*Identifier : martinsoenen.maxLinePerClass*

Guarantee that a class is no more than 100 lines long, to clearly separate roles between classes and encourage clarification.

### Max Line Per Method Rule

[](#max-line-per-method-rule)

*Identifier : martinsoenen.maxLinePerMethod*

Guarantee that a method is no more than 20 lines long, to separate roles between classes and encourage specification.

### No Basic Exception Rule

[](#no-basic-exception-rule)

*Identifier : martinsoenen.noBasicException*

Ensure that no base exceptions are thrown in order to make custom and specific exceptions everywhere for better maintainability.

### No Delete Cascade Rule (Laravel)

[](#no-delete-cascade-rule-laravel)

*Identifier : martinsoenen.noCascadeDeleteLaravel*

Prevents cascading deletions in SQL to avoid uncontrolled deletions.
This rule forces you to think about the need for a cascading deletion, and to handle such cases in your code if you need to, which also makes it possible to use the observers and events managed by the framework.

This rule only works for Laravel.
A Symfony rule is planned.

### No Generic Word Rule

[](#no-generic-word-rule)

*Identifier : martinsoenen.noGenericWord*

Prevent generic variable names such as `array`, `string`, `str`, `result`, `res`, `data` to encourage developers to use clear and detailed names such as `users`, `filteredUsers`, `usersCount`, `cars`, ...

### No Laravel Observer Rule

[](#no-laravel-observer-rule)

*Identifier : martinsoenen.noLaravelObserver*

Forbid the use of Observers in Laravel, as the behavior of observers is sometimes incomprehensible and uncontrollable.
This rule encourages the use of Events &amp; Listeners, whose behavior is similar but much more explicit and stable.

### No Try Catch Rule

[](#no-try-catch-rule)

*Identifier : martinsoenen.noTryCatch*

Prevent `try catch` usage to ensure that the user uses PHP exceptions.
This makes the code more readable and errors are handled by the framework if there is one.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance56

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~6 days

Total

3

Last Release

292d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17437652?v=4)[Martin Soenen](/maintainers/martinsoenen)[@martinsoenen](https://github.com/martinsoenen)

---

Top Contributors

[![martinsoenen](https://avatars.githubusercontent.com/u/17437652?v=4)](https://github.com/martinsoenen "martinsoenen (23 commits)")

---

Tags

laravelphpphpstanphpstan-extensionphpstan-rulesrulesphpPHPStanrules

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/martinsoenen-phpstan-custom-rules/health.svg)](https://phpackages.com/packages/martinsoenen-phpstan-custom-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)[leroy-merlin-br/coding-standard

The coding standard for PHP projects on LMBR

2137.0k10](/packages/leroy-merlin-br-coding-standard)

PHPackages © 2026

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