phpstan 浣跨敤鎸囧崡

https://medium.com/@ondrejmirtes
phpstan
姊崇悊淇鎵惧嚭甯歌浠g爜闂锛岃緭鍑轰竴涓帴鍏ユ枃妗o紝寮涓涓垎浜細涓庡悓浜嬪皬浼欎即鍒嗕韩浜ゆ祦锛屼娇浠g爜鏇寸鍚坧sr4瑙勮寖銆

  1. 瀹夎
    濡傛灉鏄瀯寤哄湪寮鍙戠幆澧冧緵鑷繁鑷祴锛岄偅涔
    composer require --dev phpstan/phpstan
    濡傛灉鏄瀯寤哄湪鐢熶骇鐜锛岄偅涔
    composer require phpstan/phpstan
    dockerfile鏂囦欢鍙兘鏄被浼艰繖鏍峰瓙鐨
FROM ***.cr.aliyuncs.com/kpos/hyperf-base:7.4

RUN apk add php7-pecl-xlswriter --repository http://nl.alpinelinux.org/alpine/edge/testing

WORKDIR /opt/www

COPY ./composer.* /opt/www/

RUN composer install --no-dev -o --prefer-dist \
    && composer clearcache \
    && composer dump-autoload -o

COPY . /opt/www

RUN composer analyse

RUN php bin/hyperf.php

ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"]
  "scripts": {
    "analyse": "phpstan analyse --memory-limit 1000M -c phpstan.neon",
  }
  1. 鍒涘缓涓涓猵hpstan.neon鏂囦欢,骞惰缃渶楂樼瓑绾9
parameters:
  level: 9
  paths:
      - src

2.1 寮鍚弗鏍兼ā寮
composer require phpstan/phpstan-strict-rules

includes:
    - vendor/phpstan/phpstan-strict-rules/rules.neon
  1. 蹇界暐鎶ラ敊
ignoreErrors:
      - '#with no value type specified in iterable type array.#'

reportUnmatchedIgnoredErrors

  1.     /**
         * @return Collection|Payment[]
         */
        public function getPayments(array $codes): Collection
        {
            return Payment::query()->whereIn('code_name', $codes)->get();
        }
    
    /**
     * @return Collection<Payment>
     */
    public function getPayments(array $codes): Collection
    {
        return Payment::query()->whereIn('code_name', $codes)->get();
    }
  1. Baseline

鏈夋椂鍊欑敤鐨刾hpstan鐗堟湰寰堟棫锛屽崌绾т箣鍚庡彂鐜颁簡鍑犵櫨鍑犲崈涓敊璇紝杩欎釜鏃跺欏彲浠ョ洿鎺ヤ娇鐢˙aseline,鏃т唬鐮佸氨绛変互鍚庢湁鏃堕棿鍐嶆敼锛屾柊鐨勪唬鐮佸氨灏嗛伒寰洿楂樼殑鏍囧噯鏉ュ紑鍙戙

vendor/bin/phpstan analyse --level 9 --configuration phpstan.neon src --generate-baseline

鐒跺悗phpstan.neon鏂囦欢澧炲姞涓鍙

includes:
  - phpstan-baseline.neon

All posts

Other pages


Deprecated: 鏂囦欢 娌℃湁 comments.php 鐨勪富棰 鑷増鏈 3.0.0 璧峰凡寮冪敤锛屼笖娌℃湁鍙敤鐨勬浛浠c 璇峰湪鎮ㄧ殑涓婚涓寘鍚竴涓 comments.php 妯℃澘銆 in /www/wwwroot/liguoqi.site/wp-includes/functions.php on line 6078

鍙戣〃鍥炲

鎮ㄧ殑鐢靛瓙閭鍦板潃涓嶄細琚叕寮銆 蹇呭~椤瑰凡鐢 * 鏍囨敞