指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

忽略phpstan对方法参数的检查:

ignoreErrors:
        	- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type array#"
        	- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ return type has no value type specified in iterable type array#"
        	- "#Property [a-zA-Z0-9\\$\\_\\\\:\\(\\)]+ type has no value type specified in iterable type array#"
        	
参考:https://github.com/phpstan/phpstan/discussions/7287

上面是之前的写法,主要目的是: 想给 $left 和 $right 类型声明,但是 array 值的类型,一直不确定,后来发现可以按下面的方式解决,原来是mixed就可以了,不用添加如上配置

    /**
     * @param array<mixed> $left
     * @param array<mixed> $right
     */
    public function compareByDate($left = [], $right = [], string $order = 'asc'): int
    {
        $dateLeft = $left['date']->getTimestamp();
        $dateRight = $right['date']->getTimestamp();

        $result = ($dateLeft < $dateRight) ? -1 : 1;

        return ('asc' == $order) ? $result : -$result;
    }