top-think / framework

ThinkPHP Framework
http://www.thinkphp.cn
Other
2.72k stars 1.05k forks source link

禁用部分 StyleCI 规则 #2987

Closed big-dream closed 5 months ago

big-dream commented 6 months ago

更改后效果预览 https://github.styleci.io/analyses/LZJaJn

一、禁用规则

phpdoc_summary

PHPDoc 摘要应以句号、感叹号或问号结束。

该规则要求注释结尾加句号,目前可考虑禁用。

/**
  * 注释文字.
  */

phpdoc_separation

相同类型的注释应紧跟在一起,不同类型的注释必须分开(空行分开)。

该规则要求不同注释类型要用空行分开,目前可考虑禁用

/**
 * 获取有效期
 *
 * @access protected
 * 
 * @param integer|DateInterval|DateTimeInterface $expire 有效期
 * 
 * @return int
 */

blank_line_after_opening_tag

确保与 PHP open 标签(<?php ?>)在同一行上没有代码,并且后面跟着一个空行。

该规则要求 <?php 后面需要一行空行,目前可考虑禁用

<?php

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]

concat_without_spaces

应使用不带空格的串联(连接符"."前后可以带空格)

该规则要求变量与字符串连接是,.前后不能有空格,目前可考虑禁用

$str = $a.'b'.$c;

二、剩余不符合规范的代码示例

integer 统一为 int,类型、变量名和描述对齐

     /**
      * 抛出HTTP异常
-     * @param integer|Response $code    状态码 或者 Response对象实例
-     * @param string           $message 错误信息
-     * @param array            $header  参数
+     * @param int|Response $code    状态码 或者 Response对象实例
+     * @param string       $message 错误信息
+     * @param array        $header  参数
      */

删除 @access @package

     /**
      * 架构方法
-     * @access public
      * @param string $rootPath 应用根目录
      */
/**
  * 配置管理类
- * @package think
  */

等号两边只保留一个空格

     public function initialize()

         $this->initialized = true;

         $this->beginTime = microtime(true);
-        $this->beginMem  = memory_get_usage();
+        $this->beginMem = memory_get_usage();

         $this->loadEnv($this->envName);
-declare(strict_types = 1);
+declare(strict_types=1);

导入顺序调整

use Psr\Container\ContainerInterface;
 use ReflectionClass;
 use ReflectionException;
-use ReflectionNamedType;
 use ReflectionFunction;
 use ReflectionFunctionAbstract;
 use ReflectionMethod;
+use ReflectionNamedType;
 use think\exception\ClassNotFoundException;
 use think\exception\FuncNotFoundException;
 use think\helper\Str;

无需参数的类补充上括号

-            static::$instance = new static;
+            static::$instance = new static();

使用单引号

-        if ($this->server('HTTP_VIA') && stristr($this->server('HTTP_VIA'), "wap")) {
+        if ($this->server('HTTP_VIA') && stristr($this->server('HTTP_VIA'), 'wap')) {