https://medium.com/@ondrejmirtes
phpstan
姊崇悊淇鎵惧嚭甯歌浠g爜闂锛岃緭鍑轰竴涓帴鍏ユ枃妗o紝寮涓涓垎浜細涓庡悓浜嬪皬浼欎即鍒嗕韩浜ゆ祦锛屼娇浠g爜鏇寸鍚坧sr4瑙勮寖銆
composer require --dev phpstan/phpstan
composer require phpstan/phpstan
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",
}
parameters:
level: 9
paths:
- src
2.1 寮鍚弗鏍兼ā寮
composer require phpstan/phpstan-strict-rules
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
ignoreErrors:
- '#with no value type specified in iterable type array.#'
reportUnmatchedIgnoredErrors
/**
* @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();
}
鏈夋椂鍊欑敤鐨刾hpstan鐗堟湰寰堟棫锛屽崌绾т箣鍚庡彂鐜颁簡鍑犵櫨鍑犲崈涓敊璇紝杩欎釜鏃跺欏彲浠ョ洿鎺ヤ娇鐢˙aseline,鏃т唬鐮佸氨绛変互鍚庢湁鏃堕棿鍐嶆敼锛屾柊鐨勪唬鐮佸氨灏嗛伒寰洿楂樼殑鏍囧噯鏉ュ紑鍙戙
vendor/bin/phpstan analyse --level 9 --configuration phpstan.neon src --generate-baseline
鐒跺悗phpstan.neon鏂囦欢澧炲姞涓鍙
includes:
- phpstan-baseline.neon
鍙戣〃鍥炲