erickskrauch/phpstan-yii2

Yii2 extension for PHPStan

dev-master 2023-11-28 09:34 UTC

This package is auto-updated.

Last update: 2024-04-28 10:19:52 UTC


README

An extension for PHPStan providing types support and rules to work with the Yii2 framework. Hardfork of proget-hq/phpstan-yii2.

Latest Version on Packagist Total Downloads Software License Build Status

What does it do?

  • Provides stub files for better analysis of array shapes.
  • Provide array shape analyse for Yii:createObject().
  • Provide analyse for the last array argument of the yii\base\Configurable class constructor.
  • Mark YII_* constants as dynamic.
  • Significantly improves support for ActiveRecord and ActiveQuery.
  • Provides correct return type for Yii::$container->get('service_id') method.
  • Provides correct return type for Yii::$app->request->headers->get('authorization') method based on the $first parameter.
  • Provides reflection extension for BaseObject's getters and setters.

Installation

To use this extension, require it in Composer:

composer require --dev erickskrauch/phpstan-yii2

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
  - vendor/erickskrauch/phpstan-yii2/extension.neon
  - vendor/erickskrauch/phpstan-yii2/rules.neon

Configuration

You have to provide the path to the configuration file for your application. For Advanced project template your path might look like this:

parameters:
  yii2:
    config_path: common/config/main.php

You may want to create a separate configuration file for PHPStan describing the services available throughout the application. But usually, common is sufficient, because it contains all the services universally available in any module of the application.