PHPackages                             macropage/phpstan-inspections - 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. macropage/phpstan-inspections

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

macropage/phpstan-inspections
=============================

A set of PHPStan rules inspired by PhpInspections (EA Extended) to help you find bugs and code smells in your PHP code.

633Java

Since Mar 27Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PHPStan Inspections
===================

[](#phpstan-inspections)

> **⚠️ Disclaimer: Use With Caution ⚠️**
>
> All PHPStan rules in this package were written with the assistance of AI. While they have been tested, it is highly likely that some rules may produce false positives or be otherwise incorrect. Please use this package with caution and thoroughly verify its findings.

This repository contains a set of PHPStan rules inspired by the popular PhpStorm plugin [PhpInspections (EA Extended)](https://github.com/kalessil/phpinspectionsea). Its goal is to bring the powerful static analysis capabilities of PhpInspections to the command line and your CI/CD pipeline through PHPStan.

This allows you to find potential bugs, performance issues, and code style violations automatically, ensuring a higher code quality across your projects.

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

[](#installation)

To use these rules, require the package via Composer:

```
composer require --dev macropage/phpstan-inspections
```

PHPStan will automatically discover the extension via `phpstan/extension-installer`.

Usage
-----

[](#usage)

Once installed, the rules are active by default. If you need to configure it manually, you can include the `rules.neon` file in your project's `phpstan.neon` configuration:

```
includes:
    - vendor/macropage/phpstan-inspections/rules/rules.neon
```

### Laravel Support

[](#laravel-support)

This package also includes rules specifically adapted for Laravel projects. For example, the `StaticInvocationViaThisLaravelRule` is optimized to work correctly with Laravel's Facades and Eloquent Models.

To use the Laravel-specific rules, include the `rules.laravel.neon` file in your `phpstan.neon` instead:

```
includes:
    - vendor/macropage/phpstan-inspections/rules/rules.laravel.neon
```

You can then run PHPStan as you normally would:

```
vendor/bin/phpstan analyse src tests
```

Origin of the Rule Logic
------------------------

[](#origin-of-the-rule-logic)

Each rule in this package is a direct port from a Java template found in the original PhpInspections (EA Extended) project. The corresponding Java source file for each rule is located in the `dev-assets/java` directory, providing a clear reference to the original logic.

**Example:**

- **Rule File:** `src/CodeStyle/AmbiguousMethodsCallsInArrayMappingRule.php`
- **Ported From:** `dev-assets/java/codeStyle/AmbiguousMethodsCallsInArrayMappingInspector.java`
- **Test Trigger File:** `dev-assets/triggers/AmbiguousMethodsCallsInArrayMappingRule_trigger.php`

Rule Set
--------

[](#rule-set)

This package includes a wide variety of rules that check for:

- Architecture-related issues
- Potential bugs and logical errors
- Performance bottlenecks
- Code style and best practice violations
- Security vulnerabilities

A complete list of all included rules can be found by browsing the `src/` directory.

Acknowledgements
----------------

[](#acknowledgements)

This project would not be possible without the incredible work done by Vladimir Reznichenko (@kalessil) on the original [PhpInspections (EA Extended)](https://github.com/kalessil/phpinspectionsea) plugin for PhpStorm. All the logic and inspiration for these rules come from that project.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a pull request or create an issue for any bugs or feature requests.

Testing
-------

[](#testing)

This project includes a test suite that validates all rules against their trigger files in a single PHPStan run (~3 seconds). See **[TESTING.md](TESTING.md)** for full documentation.

```
docker run --rm -v $(pwd):/app -w /app michabbb/frankenphplaravel:8.5 \
  bash -c 'composer install --quiet 2>/dev/null; php test_rules.php'
```

Known Issues
------------

[](#known-issues)

### PHPStan Core Bug with First-Class Callables in `for` Loops

[](#phpstan-core-bug-with-first-class-callables-in-for-loops)

There is a known bug in PHPStan's core (`TypeSpecifier::specifyTypesInCondition()`) that causes an internal error when analyzing `for` loops with First-Class Callable syntax in the condition:

```
// This will crash PHPStan (not this rule, but PHPStan itself)
for ($i = 0; $i < count(...); $i++) {
    // loop body
}
```

**Error:** `Internal error: assert(!$this->isFirstClassCallable())`

This crash occurs during PHPStan's internal type analysis before any custom rules are invoked. The `ForeachInvariantsRule` in this package has defensive guards to skip First-Class Callables, but the crash happens in PHPStan's core when it tries to analyze the loop condition.

**Workarounds:**

- Use a variable to store the count: `$count = count($array); for ($i = 0; $i < $count; $i++)`
- Use a normal function call: `for ($i = 0; $i < count($array); $i++)`
- Use `foreach` instead of `for` loops

**References:**

- [PHPStan Issue #8078](https://github.com/phpstan/phpstan/issues/8078)
- [PHPStan Issue #9994](https://github.com/phpstan/phpstan/issues/9994)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance59

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

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

---

Top Contributors

[![michabbb](https://avatars.githubusercontent.com/u/3524595?v=4)](https://github.com/michabbb "michabbb (13 commits)")

---

Tags

phpphpstan

### Embed Badge

![Health badge](/badges/macropage-phpstan-inspections/health.svg)

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

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

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