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

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

algolia/phpstan-magento
=======================

PHPStan Magento Extension

0241PHP

Since Apr 7Pushed 6y agoCompare

[ Source](https://github.com/algolia/phpstan-magento)[ Packagist](https://packagist.org/packages/algolia/phpstan-magento)[ RSS](/packages/algolia-phpstan-magento/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#bitexpertphpstan-magento)

This package provides some additional features for PHPStan to make it work for Magento 2 projects.

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

```

Include extension.neon in your project's PHPStan config:

```
includes:
	- vendor/bitexpert/phpstan-magento/extension.neon

```

Features
--------

[](#features)

1. The extension adds an class generator for factory &amp; proxy classes similar as Magento does it. When running PHPStan in context of a Magento application this is not needed if you point PHPStan also the the generated files folder. When running Magento in a context of a module, this is required so that PHPStan get's the full picture of all classes needed.
2. The extension adds an autoloader for "mocked" classes. These are classes that replace the Magento specific implementations to fix problems with type hints or missing methods in interfaces and such. The autoloader will check if a class, interface or trait exists locally in the extension. If so, it will load the local version instead of the one being shipped by Magento. Once those problems are fixed in Magento, those mocks can be removed again.
3. A type extension was added so that `ObjectManager` calls return the correct return type.
4. For some classes like the `DataObject` or the `SessionManager` logic was added to be able to support magic method calls.

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

[](#known-issues)

Below is a list of known issues when using this extension:

### PHPStan shim does not generate factories, proxies, etc.

[](#phpstan-shim-does-not-generate-factories-proxies-etc)

This is because the PHPStan shim is included as a phar archive and does therefore not support overriding certain methods in it's namespace. The current known fix for this is to manually load the autoloader that comes with this extension.

Create a file in your project (for example `phpstan.php`) with the following content:

```
