PHPackages                             devenjahnke/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. devenjahnke/phpstan-rules

ActivePhpstan-extension[Utility &amp; Helpers](/categories/utility)

devenjahnke/phpstan-rules
=========================

My Custom PHPStan Rules

1.1.0(1y ago)09MITPHPPHP ^8.2

Since Jun 25Pushed 1y agoCompare

[ Source](https://github.com/devenjahnke/phpstan-rules)[ Packagist](https://packagist.org/packages/devenjahnke/phpstan-rules)[ RSS](/packages/devenjahnke-phpstan-rules/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

DevenJahnke's PHPStan Rules
===========================

[](#devenjahnkes-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 devenjahnke/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/devenjahnke/phpstan-rules/rules.neon

        parameters:
            # 1) Enable/disable test rules:
            devenjahnke:
                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:
            devenjahnke:
                tests:
                    testCaseClass: App\Tests\TestCase
        ```
    - If you want to **disable** all PHPStan test rules, set:

        ```
        parameters:
            devenjahnke:
                tests:
                    enabled: false
        ```
    - Leaving `devenjahnke.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:

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

        ```

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

---

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

[](#rule-descriptions--examples)

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

### `DevenJahnke\PHPStan\Rules\Enums\EnumCasePascalCaseRule`

[](#devenjahnkephpstanrulesenumsenumcasepascalcaserule)

- **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;
    }
    ```

### `DevenJahnke\PHPStan\Rules\Tests\ClassMustExtendTestCaseRule`

[](#devenjahnkephpstanrulestestsclassmustextendtestcaserule)

- **Conditional**: Only runs when `devenjahnke.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: devenjahnke.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
    ```

### `DevenJahnke\PHPStan\Rules\Tests\MethodNamePrefixRule`

[](#devenjahnkephpstanrulestestsmethodnameprefixrule)

- **Conditional**: Only runs when `devenjahnke.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);
    }
    ```

### `DevenJahnke\PHPStan\Rules\Tests\MethodNameSnakeCaseRule`

[](#devenjahnkephpstanrulestestsmethodnamesnakecaserule)

- **Conditional**: Only runs when `devenjahnke.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

29

—

LowBetter than 57% of packages

Maintenance49

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Total

2

Last Release

373d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/903c98c0b043eb64d151b504bfbadff683a484e1e2cce65b6a6d56dee0380f8d?d=identicon)[devenjahnke](/maintainers/devenjahnke)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[deptrac/deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

3.0k8.8M118](/packages/deptrac-deptrac)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

79475.7M2.2k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

67272.8M1.4k](/packages/phpstan-phpstan-doctrine)[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87718.9k56](/packages/ticketswap-phpstan-error-formatter)[slam/phpstan-extensions

Slam extension of phpstan

712.6M81](/packages/slam-phpstan-extensions)[ec-europa/toolkit

Toolkit packaged for Drupal projects based on Robo.

40252.8k34](/packages/ec-europa-toolkit)

PHPackages © 2026

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