• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Magento specific extension for PHPStan

bitexpert/phpstan-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 Coverage Status installs on Packagist

Requirements

PHP: PHP 7.2 or higher

Magento: Magento 2.3.0 or higher

PHPStan: PHPStan 1.10

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 ~1.10 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 configuration

If you're using Composer >= 2.2.0 you have to allow the execution of composer plugins (see allow-plugins section) 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

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 & configuration process? Read the blog post at M.academy about Static Analysis in Magento with PHPStan.

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 what options PHPStan allows you to configure.

Feature overview

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

  • Class generator for factory & 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.

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?

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

License

PHPStan Magento Extension is released under the MIT License.

More Repositories

1

magento2-force-login

Force Customer Login Module for Magento 2
PHP
166
star
2

disco

PSR-11 compatible Dependency Injection Container for PHP.
PHP
139
star
3

adrenaline

[DEPRECATED] A PSR-7 micro framework built on top of the Adroit middleware to speed up your development ;)
PHP
31
star
4

adroit

[DEPRECATED] ADR/PSR-7 middleware
PHP
27
star
5

magerun2-list-api-endpoints

Plugin for netz98 Magerun2 to list all API endpoints
PHP
16
star
6

phing-securitychecker

[DEPRECATED] Security Checker Phing Task
PHP
15
star
7

eclipse-smartsprites

[DEPRECATED] Eclipse Plugin offering Smartsprites integration
Java
11
star
8

etcetera

Extract Transform Library
PHP
9
star
9

ng2-combobox

[DEPRECATED] The only true Angular Combobox component ;)
TypeScript
9
star
10

magerun2-password-normalizer

n98-Magerun2 Plugin for normalizing all customer-email-addresses and passwords
PHP
9
star
11

eclipse-vagrant

[DEPRECATED] Eclipse Vagrant Plugin
Java
9
star
12

captainhook-infection

Captain Hook Plugin to run InfectionPHP only against the changed files of a commit
PHP
9
star
13

composer-phive-bridge

PHP
7
star
14

liquibase-phing

[DEPRECATED] Phing tasks to interact with Liquibase for database change management
PHP
7
star
15

prophiler-psr7-middleware

[DEPRECATED] Prophiler PSR7 Middleware
PHP
7
star
16

captainhook-validateauthor

Captain Hook Plugin to check if commit author is valid (e.g. email in whitelist)
PHP
7
star
17

addItEasy

[DEPRECATED] addItEasy - a PSR-7 compatible flat file CMS
PHP
7
star
18

slf4psrlog

Simple Logging Facade for Loggers implementing PSR-3 logging interface.
PHP
6
star
19

html5-offline-demo

[DEPRECATED] HTML5 Offline Todolist Demo
JavaScript
5
star
20

composer-authstore-plugin

[DEPRECATED] Composer Authstore plugin
PHP
5
star
21

mntyjs

[DEPRECATED] Lightweight plugin system based on require.js, jQuery and Base.js.
JavaScript
5
star
22

pathfinder

[DEPRECATED] A PSR-7 based router
PHP
5
star
23

ssbjs

Simple Service Bus for Javascript
TypeScript
5
star
24

disco-demos

Demo applications to showcase how to use Disco.
4
star
25

captainhook-rejectpush

Captain Hook Plugin to reject a remote push when certain commit Ids are found in history
PHP
4
star
26

grunt-mntyjs

[DEPRECATED] Grunt task for mnty.js
JavaScript
4
star
27

sulu-securitytxt-bundle

Sulu Bundle to manage security.txt files
PHP
4
star
28

eclipse-yuicompressor

[DEPRECATED] Eclipse YUICompressor Plugin
Java
4
star
29

eclipse-composer

[DEPRECATED] Eclipse Plugin offering Composer integration
4
star
30

cs-jshint

[DEPRECATED] bitExpert jshint configuration
3
star
31

just-run-phing

[DEPRECATED] Allow developers to "just run phing."
3
star
32

typo3-basicauth

TYPO3 Basic Auth extension
PHP
3
star
33

sylius-force-login

Force Customer Login Plugin for Sylius
PHP
3
star
34

cs-scsslint

[DEPRECATED] bitExpert scsslint style configuration
2
star
35

silex-twig-translation

[DEPRECATED] Silex / Twig extension to deal with Symfony/Translation in templates.
PHP
2
star
36

mattermost-client-node

[DEPRECATED] Mattermost client for node js
TypeScript
2
star
37

eclipse-svn-export

[DEPRECATED] Eclipse Plugin to export files based on their svn revisions
Java
2
star
38

specialist

[DEPRECATED] A simple array container implementing container-interop. Array all the things!
PHP
2
star
39

etcetera-demo

etcetera demo project
PHP
1
star
40

psql-nosql-workshop-dwx16

Developer Week 2016 PostgreSQL / NoSQL Dev Session
1
star
41

testiat-api-client-node

[DEPRECATED]
JavaScript
1
star
42

profitbricks-php-cli

[DEPRECATED] PHP CLI Client to interact with the profitbricks API
PHP
1
star
43

testiat-api-client-php

[DEPRECATED]
PHP
1
star
44

cs-jscs

[DEPRECATED] bitExpert jscs configuration
JavaScript
1
star
45

profitbricks-php-sdk

[DEPRECATED] PHP SDK for the profitbricks API
PHP
1
star
46

composer-webasset-installer

[DEPRECATED] Composer Webasset Installer
PHP
1
star
47

oauth2-server-storage-dbal

[DEPRECATED] Dbal storage implementation for OAuth 2.0 Server
PHP
1
star
48

ngx-radial-progress

[DEPRECATED]
TypeScript
1
star