定制 zebra-north/phpcs-short-types 二次开发

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

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

zebra-north/phpcs-short-types

最新稳定版本:v1.0.1

Composer 安装命令:

composer require zebra-north/phpcs-short-types

包简介

Require the use of short scalar type names (bool, int) in comments, instead of long names (boolean, integer).

README 文档

README

PHP Codesniffer requires that scalar types be written in their long form, eg. boolean or integer.

As of PHP 7+, scalars are required to be written in their short form, eg. bool or int.

This patch allows you to use the short form in doc-block comments.

Before:

/**
 * Test function.
 *
 * @param integer $test A numeric argument.
 *
 * @return boolean Returns true or false.
 */
function test(int $test): bool
{
    return false;
}

After:

/**
 * Test function.
 *
 * @param int $test A numeric argument.
 *
 * @return bool Returns true or false.
 */
function test(int $test): bool
{
    return false;
}

Errors Fixed

  • Squiz.Commenting.FunctionComment.IncorrectParamVarName
    • Expected "boolean" but found "bool" for parameter type
    • Expected "integer" but found "int" for parameter type
  • Squiz.Commenting.VariableComment.IncorrectVarType
    • Expected "boolean" but found "bool" for @var tag in member variable comment
    • Expected "integer" but found "int" for @var tag in member variable comment
  • Squiz.Commenting.FunctionComment.InvalidReturn
    • Expected "boolean" but found "bool" for function return type
    • Expected "integer" but found "int" for function return type

Installation

  1. Install into composer with: composer require --dev zebra-north/phpcs-short-types
  2. Edit your project's phpcs.xml to add a bootstrap file:
<?xml version="1.0"?>
<ruleset>

    <arg name="bootstrap" value="vendor/zebra-north/phpcs-short-types/short-types.php"/>

    ...

</ruleset>

Known Issues

This will not suggest bool/int if you have used boolean/integer - that would require patching PHP Codesniffer. A patch has been created, but not yet merged:

squizlabs/PHP_CodeSniffer#3139

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-20