8000 GitHub - yii2-extensions/phpstan: PHPStan plugin.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PHPStan plugin.

License

Notifications You must be signed in to change notification settings

yii2-extensions/phpstan

Extension for PHPStan.

PHP-Version Yii-22.0.52 Yii2-22 PHPUnit Static-Analysis Codecov

Installation

The preferred way to install this extension is through composer.

Either run

composer require --dev --prefer-dist yii2-extensions/phpstan:^0.2

or add

"yii2-extensions/phpstan": "^0.2"

Usage

This extension provides enhanced static analysis for Yii2 applications by adding:

  • Container service resolution with proper type inference.
  • Dynamic method return types for ActiveRecord and ActiveQuery.
  • Header collection dynamic methods support.
  • Property reflection extensions for Application, Request, Response, and User components.
  • Service map integration for dependency injection analysis.

Basic Configuration

To use this extension, you need to add the following configuration to your phpstan.neon file:

includes:
    - vendor/yii2-extensions/phpstan/extension.neon

parameters:
    bootstrapFiles:
        - tests/bootstrap.php

    level: 5

    paths:
        - src

    # Exclude paths from analysis
    excludePaths:
        - c3.php
        - requirements.php
        - config
        - tests
        - vendor

    yii2:
        # Path to your `Yii2` configuration file (optional)
        # If not provided or empty, will work without explicit configuration 
        config_path: %currentWorkingDirectory%/config/test.php

Dynamic Constants Configuration

The extension automatically recognizes common Yii2 dynamic constants:

  • YII_DEBUG
  • YII_ENV
  • YII_ENV_DEV
  • YII_ENV_PROD
  • YII_ENV_TEST

If you need to add additional dynamic constants, you can extend the configuration:

includes:
    - vendor/yii2-extensions/phpstan/extension.neon

parameters:
    # Your existing dynamic constants will be merged with the extension's defaults
    dynamicConstantNames:
        - YII_DEBUG         # Already included by the extension
        - YII_ENV           # Already included by the extension
        - YII_ENV_DEV       # Already included by the extension
        - YII_ENV_PROD      # Already included by the extension
        - YII_ENV_TEST      # Already included by the extension
        - MY_CUSTOM_CONSTANT
        - ANOTHER_CONSTANT

    yii2:
        config_path: %currentWorkingDirectory%/config/test.php

Note: When you define dynamicConstantNames in your configuration, it replaces the extension's default constants. To maintain the Yii2 constants recognition, you must include them explicitly along with your custom constants, as shown above.

Advanced Configuration Example

includes:
    - vendor/yii2-extensions/phpstan/extension.neon

parameters:
    bootstrapFiles:
        - tests/bootstrap.php

    # Complete dynamic constants list (extension defaults + custom)
    dynamicConstantNames:
        - YII_DEBUG
        - YII_ENV
        - YII_ENV_DEV
        - YII_ENV_PROD
        - YII_ENV_TEST
        - APP_VERSION
        - MAINTENANCE_MODE        

    level: 8    
    
    paths:
        - src
        - controllers
        - models
        - widgets

    excludePaths:
        - src/legacy
        - tests/_support
        - vendor

    yii2:
        config_path: %currentWorkingDirectory%/config/web.php

Quality code

phpstan-level style-ci

Testing

Check the documentation testing to learn about testing.

Our social networks

Twitter

License

BSD-3-Clause license. Please see License File for more information.

Fork

This package is a fork of proget-hq/phpstan-yii2 with some corrections.

About

PHPStan plugin.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •  

Languages

0