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

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

aryeohq/phpstan-rules
=====================

 Aryeo's Custom PHPStan Rules

1.3.0(10mo ago)15.8kMITPHPPHP ^8.2

Since May 27Pushed 10mo agoCompare

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

READMEChangelog (9)Dependencies (5)Versions (10)Used By (0)

Aryeo's PHPStan Rules
=====================

[](#aryeos-phpstan-rules)

How to Install &amp; Use in Your Project
----------------------------------------

[](#how-to-install--use-in-your-project)

Follow these steps to integrate this custom‐rule pack into any PHP project running PHPStan:

1. **Require via Composer** (adjust package name as needed):

    ```
    composer require --dev aryeo/phpstan-rules
    ```
2. **Add (or merge) `rules.neon` into your application’s PHPStan config**:

    - In your project root, you probably have a `phpstan.neon` or `phpstan.neon.dist`.
    - Ensure it includes this package’s `rules.neon`. For example:

        ```
        # phpstan.neon.dist

        includes:
            - vendor/aryeo/phpstan-rules/rules.neon

        parameters:
            # 1) Enable/disable test rules:
            aryeo:
                tests:
                    enabled: true
                    # Override TestCase class if needed
                    testCaseClass: App\Tests\TestCase

            # 2) Your other PHPStan settings:
            level: max
            paths:
                - src
                - tests
        ```
    - The `includes:` line loads all sections from the package’s `rules.neon` (including `conditionalTags`, `parameters`, `parametersSchema`, and `services`).
3. **Override parameters (optional)**:

    - If your project’s tests extend from `App\Tests\TestCase`, set:

        ```
        parameters:
            aryeo:
                tests:
                    testCaseClass: App\Tests\TestCase
        ```
    - If you want to **disable** all PHPStan test rules, set:

        ```
        parameters:
            aryeo:
                tests:
                    enabled: false
        ```
    - Leaving `aryeo.tests.enabled` out entirely will default to `true` (because the package’s `rules.neon` has `enabled: true` by default), so you only need to override it when you want it off.
4. **Run PHPStan** as usual:

    ```
    vendor/bin/phpstan analyse -c phpstan.neon.dist
    ```

    - If you kept the default `testCaseClass: Tests\TestCase` but your project uses a different namespace, you will see errors like:

        ```
        ClassAryeo\PHPStan\Rules\Tests\ClassMustExtendTestCaseRule:
        Class App\Tests\SomeTest does not extend Tests\TestCase

        ```

        In that case, update `aryeo.tests.testCaseClass` accordingly.

---

Rule Descriptions &amp; Examples
--------------------------------

[](#rule-descriptions--examples)

Below is a quick summary of what each rule does, plus usage examples.

### `Aryeo\PHPStan\Rules\Enums\EnumCasePascalCaseRule`

[](#aryeophpstanrulesenumsenumcasepascalcaserule)

- **Always active** (no conditional toggle).
- **Enforces**: Every Enum `case` name must be PascalCase.
- **Why?** PHPStan’s default `EnumCase` rule focuses on visibility or value uniqueness, but this custom rule ensures stylistic consistency across your codebase.
- **Example Violation**:

    ```
    enum Status: string
    {
        case pending;         // invalid: “pending” is not PascalCase
        case OrderPickedUp;   // invalid: starts with uppercase but next word not separated by capital
        case Shipped;         // valid if that’s exactly PascalCase (single‐word “Shipped”)
    }
    ```
- **Fix**:

    ```
    enum Status: string
    {
    -    case pending;
    -    case OrderPickedUp;
    +    case Pending;
    +    case OrderPickedUp;   // if you intended “OrderPickedUp” as PascalCase, ensure proper casing
        case Shipped;
    }
    ```

### `Aryeo\PHPStan\Rules\Tests\ClassMustExtendTestCaseRule`

[](#aryeophpstanrulestestsclassmustextendtestcaserule)

- **Conditional**: Only runs when `aryeo.tests.enabled` = `true`.
- **Constructor Argument**: `$testCaseClass` (e.g., `'Tests\TestCase'` or `'App\Tests\TestCase'`).
- **Enforces**: Every class under your `tests/` directory (or any file matching `*Test.php`) must extend the given base test case class.
- **Why?** Some teams create a `BaseTestCase` or `TestCase` with common setup/teardown. This rule ensures no test accidentally extends `\PHPUnit\Framework\TestCase` directly or some other class.
- **Example Violation**:

    ```
    // Assume: aryeo.tests.testCaseClass = 'App\Tests\TestCase'
    namespace App\Tests\Feature;

    use PHPUnit\Framework\TestCase;

    class UserTest extends TestCase
    {
        public function testSomething()
        {
            $this->assertTrue(true);
        }
    }
    ```

    - **Error**: `Class UserTest does not extend App\Tests\TestCase.`
- **Fix**:

    ```
    use PHPUnit\Framework\TestCase;

    class UserTest extends TestCase
    ```

    to:

    ```
    use App\Tests\TestCase;  // your own base test case

    class UserTest extends TestCase
    ```

### `Aryeo\PHPStan\Rules\Tests\MethodNamePrefixRule`

[](#aryeophpstanrulestestsmethodnameprefixrule)

- **Conditional**: Only runs when `aryeo.tests.enabled` = `true`.
- **Constructor Argument**: `$testCaseClass`.
- **Enforces**: In any class extending `$testCaseClass`, all public test methods must start with a given prefix (e.g., `test`).
- **Why?** PHPUnit’s default behavior is to look for methods that start with `test`, but you may have configured fallback annotations, or you want to enforce a uniform method naming convention. This rule ensures that any test method is named `testSomething…` rather than `somethingTest()` or `it_does_something()`.
- **Example Violation**:

    ```
    class UserTest extends App\Tests\TestCase
    {
        public function doesSomething() // invalid: missing “test” prefix
        {
            $this->assertTrue(true);
        }

        public function testItWorks() // valid
        {
            $this->assertTrue(true);
        }
    }
    ```
- **Fix**: Rename method to:

    ```
    public function testDoesSomething()
    {
        $this->assertTrue(true);
    }
    ```

### `Aryeo\PHPStan\Rules\Tests\MethodNameSnakeCaseRule`

[](#aryeophpstanrulestestsmethodnamesnakecaserule)

- **Conditional**: Only runs when `aryeo.tests.enabled` = `true`.
- **Constructor Argument**: `$testCaseClass`.
- **Enforces**: Test method names in classes extending `$testCaseClass` must use `snake_case` rather than `camelCase` or `PascalCase`.
- **Why?** Some teams prefer writing test names in snake\_case so that method names—when read—describe behavior in a consistent way (e.g., `test_user_can_register`). If your team enforces snake\_case, this rule flags camelCase or PascalCase.
- **Example Violation**:

    ```
    class UserTest extends App\Tests\TestCase
    {
        public function testUserCanRegister() // invalid: camelCase/PascalCase
        {
            $this->assertTrue(true);
        }

        public function test_user_can_login()  // valid: snake_case
        {
            $this->assertTrue(true);
        }
    }
    ```
- **Fix**: Convert to snake\_case:

    ```
    - public function testUserCanRegister()
    + public function test_user_can_register()
    {
        $this->assertTrue(true);
    }
    ```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance54

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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 ~4 days

Total

9

Last Release

320d ago

PHP version history (3 changes)1.0.0PHP ^7.4 || ^8.0

1.2.0PHP ^8.0

1.2.3PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/c753ed243e6ca82419d8364d26a9f3143f7d90a6c50c8a677f9a5db48beb21f3?d=identicon)[aryeo](/maintainers/aryeo)

---

Top Contributors

[![devenjahnke](https://avatars.githubusercontent.com/u/10586846?v=4)](https://github.com/devenjahnke "devenjahnke (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/aryeohq-phpstan-rules/health.svg)](https://phpackages.com/packages/aryeohq-phpstan-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

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

Doctrine extensions for PHPStan

66466.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.

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

Drupal extension and rules for PHPStan

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

PHPackages © 2026

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