定制 prestashop/phpstan-prestashop 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prestashop/phpstan-prestashop

最新稳定版本:2.0.0

Composer 安装命令:

composer require prestashop/phpstan-prestashop

包简介

PrestaShop extension for PHPStan

README 文档

README

PHP tests Static Analysis GitHub release GitHub license

Content

This PHPStan extension adds custom rules to PHPStan:

  • ClassConstantsMustHaveVisibilityRule
  • UseStrictTypesForNewClassesRule
  • UseTypeHintForNewMethodsRule
  • UseTypedReturnForNewMethodsRule

Installation

Install the dependencies with Composer:

composer install

Tests

Install the dev dependencies with Composer:

composer install --dev

Run tests using PHPUnit:

vendor/bin/phpunit -c tests/phpunit.xml tests

Rules are tested using PHPStan RuleTestCase.

Run static analysis with PHPStan:

vendor/bin/phpstan analyse src tests/Rules -l 5

Extension is validated using a real PHPStan phar

bash tests/Acceptance/run.sh

Use in a project

To use this extension, first require it in Composer:

composer require --dev prestashop/phpstan-prestashop

Then you need to include extension.neon in your project's PHPStan config:

includes:
    - vendor/prestashop/phpstan-prestashop/extension.neon

Required settings

UseStrictTypesForNewClassesRule

Rule UseStrictTypesForNewClassesRule requires loading of a configuration asset.

You need to provide a service that is an instance of PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface, named @strictTypesForNewClassesRuleConfigurationFileLoader. It should load an array of classes for which the UseStrictTypesForNewClassesRule should not be applied.

There is two available implementations: PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader and PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader.

Example with PHPConfigurationFileLoader:

services:
    strictTypesForNewClassesRuleConfigurationFileLoader:
        class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
        arguments:
            - .github/workflows/phpstan/exclude-class-list.php

UseTypedReturnForNewMethodsRule

Rule UseTypedReturnForNewMethodsRule requires loading of a configuration asset.

You need to provide a service that is an instance of PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface, named @returnTypesForNewMethodsRuleConfigurationFileLoader. It should load an array of class methods for which the UseTypedReturnForNewMethodsRule should not be applied.

There is two available implementations: PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader and PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader.

Example with PHPConfigurationFileLoader:

services:
    returnTypesForNewMethodsRuleConfigurationFileLoader:
        class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
        arguments:
            - .github/workflows/phpstan/exclude-return-functions-list.php

UseTypeHintForNewMethodsRule

Similarly to UseTypedReturnForNewMethodsRule, rule UseTypeHintForNewMethodsRule requires loading of an instance of PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface, named @typeHintsForNewMethodsRuleConfigurationFileLoader. It should load an array of class methods for which the UseTypeHintForNewMethodsRule should not be applied.

There is two available implementations: PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader and PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader.

Example with PHPConfigurationFileLoader:

services:
    typeHintsForNewMethodsRuleConfigurationFileLoader:
        class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
        arguments:
            - .github/workflows/phpstan/exclude-typehint-functions-list.php

统计信息

  • 总下载量: 1.83M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 10
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-11