xactsystems/phpstan-extensions 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

xactsystems/phpstan-extensions

最新稳定版本:v1.0.2

Composer 安装命令:

composer require --dev xactsystems/phpstan-extensions

包简介

A collection of PHPStan extensions found useful in our projects.

README 文档

README

This repo contains some useful PHPStan extension for detecting errors in your code. The currently list of rules is:

UnusedClassRule

UnusedTraitRule

Install

composer require xactsystems/phpstan-extensions --dev

Usage

With PHPStan extension installer, everything is ready to run.

Otherwise manually enable the extension:

# phpstan.neon
include:
    'vendor/xactsystems/phpstan-extensions/config/extension.neon'
    

Rules

UnusedClassRule

This rule scans for class declarations and use statements. If a class is declared but not used within the scanned source files, an error is generated.

Disabling the rule

You can disable scanning classes as follows:

# phpstan.neon
parameters:
    unused_classes:
        classes: false

Excluding files

You can exclude directories and individual files from being scanned by this rule:

# phpstan.neon
parameters:
    unused_classes:
        excludePaths:
            - 'src/Controller'
            - 'src/MyUnusedClass.php'

Excluding Services

By default, some known service and framework classes are excluded. There are a number of base classes from Symfony, Doctrine and PHPUnit that checked and, if matched, the class being analysed is ignored.

To disable this, set the excludeFrameworks property to false:

# phpstan.neon
parameters:
    unused_classes:
        excludeFrameworks: false

This list will change as new frameworks and classes are added. Please look at the source code in src/Frameworks for a list of base classes that are excluded.

If you want add a custom list of base classes to ignore, use the baseClassExcludes property:

# phpstan.neon
parameters:
    unused_classes:
        baseClassExcludes:
            - 'App\Service\MyAbstractService'
            - 'App\DI\MyDIClass'

Entries in baseClassExcludes are excluded regardless of the excludeFrameworks property value.

UnusedTraitRule

This rule scans for trait declarations and use statements. If a trait is declared but not used within the scanned source files, an error is generated.

Disabling the rule

You can disable scanning traits as follows:

# phpstan.neon
parameters:
    unused_classes:
        traits: false

Excluding files

You can exclude directories and individual files from being scanned by this rule using the excludePaths parameter as shown above.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-03