はじめに
こんにちは、エンジニアのkeitaMaxです。
前回DockerでCakePHPの環境を整えて、最初の画面表示まで行いました。
今回はPHPStanを使用できるようにしたいと思います。
インストール
以下のコマンドでインストールします。
composer require --dev phpstan/phpstan
実行
docker compose exec app bash
上のコマンドでコンテナの中に入った後、以下コマンドでPHPStanを実行することができます。
./vendor/bin/phpstan analyse
実行すると以下のように解析をしてくれます。
root@4ab649b0155e:/app# ./vendor/bin/phpstan analyse
Note: Using configuration file /app/phpstan.neon.
⚠️ You're using a deprecated config option checkGenericClassInNonGenericObjectType ⚠️️
It's strongly recommended to remove it from your configuration file
and add the missing generic typehints.
If you want to continue ignoring missing typehints from generics,
add missingType.generics error identifier to your ignoreErrors:
parameters:
ignoreErrors:
-
identifier: missingType.generics
7/7 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] No errors
root@4ab649b0155e:/app#
また、以下のコマンドでも実行可能です。
composer stan
設定ファイル
設定ファイルは、'composer.json'と同じ階層にあるphpstan.neon
です。
以下のように設定してあります。
phpstan.neon
parameters:
level: 8
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/
おわりに
次回はGitHubAcrtionsを使ってGitHub上で実行したいと思います。
この記事での質問や、間違っている、もっといい方法があるといったご意見などありましたらご指摘していただけると幸いです。
最後まで読んでいただきありがとうございました!
参考
次の記事