PHPackages                             bitexpert/phpstan-magento - 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. bitexpert/phpstan-magento

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

bitexpert/phpstan-magento
=========================

PHPStan Magento Extension

v0.42.0(1y ago)1482.5M↓37.2%28[9 issues](https://github.com/bitExpert/phpstan-magento/issues)[5 PRs](https://github.com/bitExpert/phpstan-magento/pulls)20MITPHPPHP ^7.2.0 || ^8.1.0CI failing

Since Apr 18Pushed 1mo ago9 watchersCompare

[ Source](https://github.com/bitExpert/phpstan-magento)[ Packagist](https://packagist.org/packages/bitexpert/phpstan-magento)[ RSS](/packages/bitexpert-phpstan-magento/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (16)Versions (76)Used By (20)

bitexpert/phpstan-magento
=========================

[](#bitexpertphpstan-magento)

This package provides some additional features for PHPStan to make it work for Magento 2 projects. You can use this PHPStan extension for both Magento module projects and Magento application projects.

[![Build Status](https://github.com/bitExpert/phpstan-magento/workflows/ci/badge.svg?branch=master)](https://github.com/bitExpert/phpstan-magento/actions)[![Coverage Status](https://camo.githubusercontent.com/89848e4add9b521b5fbdd40f9c454fd39213d3ded719e469156c5ee3c89d621c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6269744578706572742f7068707374616e2d6d6167656e746f2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bitExpert/phpstan-magento?branch=master)[![installs on Packagist](https://camo.githubusercontent.com/eeb3e2b8fa781f42ac60195f61a1e661cef61ad06f705aed07e754c3778ebfd4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6269744578706572742f7068707374616e2d6d6167656e746f)](https://packagist.org/packages/bitExpert/phpstan-magento/)[![Mastodon Follow](https://camo.githubusercontent.com/c2abd2d790b2fdf042e992e8872c59044086bdb16b119a61d8526d6238c3c2ba/68747470733a2f2f696d672e736869656c64732e696f2f6d6173746f646f6e2f666f6c6c6f772f3130393430383638313234363937323730303f646f6d61696e3d68747470733a2f2f726865696e6e65636b61722e736f6369616c)](https://rheinneckar.social/@bitexpert)

Requirements
------------

[](#requirements)

PHP: PHP 7.2 or higher

Magento: Magento 2.3.0 or higher

PHPStan: PHPStan 2.0 or higher

If you are using a Magento version that requires an older version of PHPStan (e.g. 0.12.77), you need to manually upgrade it before installing this extension. in your composer.json Change the PHPStan version to `~2.0` and run:

```
composer update phpstan/phpstan --with-all-dependencies

```

This PHPStan extension needs to be registered with PHPStan so that the extension gets loaded properly. The easiest way to do this is to install the `phpstan/extension-installer` package as follows:

```
composer.phar require --dev phpstan/extension-installer

```

 Composer Allow-Plugins configurationIf you're using Composer &gt;= 2.2.0 you have to allow the execution of composer plugins ([see allow-plugins section](https://getcomposer.org/doc/06-config.md#allow-plugins)) as follows:

```
  - Installing phpstan/extension-installer (1.1.0): Extracting archive
phpstan/extension-installer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "phpstan/extension-installer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y

```

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

[](#installation)

The preferred way of installing `bitexpert/phpstan-magento` is through Composer. You can add `bitexpert/phpstan-magento` as a dev dependency, as follows:

```
composer.phar require --dev bitexpert/phpstan-magento

```

> Want a full walk-through of the installation &amp; configuration process? Read the blog post at M.academy about [Static Analysis in Magento with PHPStan](https://m.academy/blog/static-analysis-magento-phpstan/).

### PHPStan configuration

[](#phpstan-configuration)

If you have not already a PHPStan configuration file `phpstan.neon` in your project, create a new empty file next to your `composer.json` file.

See [here](https://phpstan.org/config-reference) what options PHPStan allows you to configure.

Feature overview
----------------

[](#feature-overview)

This PHPStan extension works for both Magento module projects and Magento application projects.

- Class generator for factory &amp; proxy classes
- Mocked classes autoloader
- TestFramework autoloader
- Type hints
    - TestFramework ObjectManager type hints
    - ObjectManager type hints
- Magic method calls
- Extension attributes
- PHPStan rules
    - Service contracts
    - Resource Models should be used directly
    - Collections should be used directly via factory
    - Do not use setTemplate in Block classes

For a detailed overview, check the feature documentation [here](docs/features.md).

Contribute
----------

[](#contribute)

Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and adapt the documentation.

Want To Contribute?
-------------------

[](#want-to-contribute)

If you feel that you have something to share, then we’d love to have you. Check out [the contributing guide](CONTRIBUTING.md) to find out how, as well as what we expect from you.

License
-------

[](#license)

PHPStan Magento Extension is released under the MIT License.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance72

Regular maintenance activity

Popularity59

Moderate usage in the ecosystem

Community42

Growing community involvement

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 70.2% 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 ~48 days

Recently: every ~77 days

Total

39

Last Release

388d ago

PHP version history (4 changes)v0.1.0PHP ^7.2.0

v0.11.0PHP ^7.2.0 | ^8.0.0

v0.14.0PHP ^7.2.0 || ^8.0.0

v0.20.0PHP ^7.2.0 || ^8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1adf0ab660536efce10aeb97f0c90ec881110b64fbd23429fa945190df0def56?d=identicon)[shochdoerfer](/maintainers/shochdoerfer)

---

Top Contributors

[![shochdoerfer](https://avatars.githubusercontent.com/u/596449?v=4)](https://github.com/shochdoerfer "shochdoerfer (449 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (93 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (37 commits)")[![mattwellss](https://avatars.githubusercontent.com/u/1776257?v=4)](https://github.com/mattwellss "mattwellss (24 commits)")[![hostep](https://avatars.githubusercontent.com/u/85479?v=4)](https://github.com/hostep "hostep (13 commits)")[![BrentRobert](https://avatars.githubusercontent.com/u/6866325?v=4)](https://github.com/BrentRobert "BrentRobert (6 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (5 commits)")[![sprankhub](https://avatars.githubusercontent.com/u/930199?v=4)](https://github.com/sprankhub "sprankhub (3 commits)")[![piotrmarkiewicz-vaimo](https://avatars.githubusercontent.com/u/232579128?v=4)](https://github.com/piotrmarkiewicz-vaimo "piotrmarkiewicz-vaimo (2 commits)")[![torhoehn](https://avatars.githubusercontent.com/u/1945725?v=4)](https://github.com/torhoehn "torhoehn (2 commits)")[![kanduvisla](https://avatars.githubusercontent.com/u/346681?v=4)](https://github.com/kanduvisla "kanduvisla (1 commits)")[![stijnbernards](https://avatars.githubusercontent.com/u/6909174?v=4)](https://github.com/stijnbernards "stijnbernards (1 commits)")[![indykoning](https://avatars.githubusercontent.com/u/15870933?v=4)](https://github.com/indykoning "indykoning (1 commits)")[![markshust](https://avatars.githubusercontent.com/u/437029?v=4)](https://github.com/markshust "markshust (1 commits)")[![jbrada](https://avatars.githubusercontent.com/u/7402947?v=4)](https://github.com/jbrada "jbrada (1 commits)")[![navarr](https://avatars.githubusercontent.com/u/145128?v=4)](https://github.com/navarr "navarr (1 commits)")

---

Tags

magento2phpphpstanphpstan-extension

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bitexpert-phpstan-magento/health.svg)

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.4k](/packages/larastan-larastan)[mglaman/phpstan-drupal

Drupal extension and rules for PHPStan

20830.6M166](/packages/mglaman-phpstan-drupal)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

78973.3M2.0k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

66970.7M1.3k](/packages/phpstan-phpstan-doctrine)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9134.1M24](/packages/phparkitect-phparkitect)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

4753.1M82](/packages/shipmonk-dead-code-detector)

PHPackages © 2026

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