LoginSignup
1
0

More than 1 year has passed since last update.

laravel larastanを導入してみる

Last updated at Posted at 2023-03-10

概要

  • laravel用PHPStanのlarastanを導入してみる。

前提

  • 各バージョンが下記以上であること
    • PHP: 8.0
    • laravel: 9.0

larastan(PHPStan)はプロジェクトの途中でも入れられる

  • level0から始められる
    • まずは0からスタートして出たエラーを解消 → レベルを1にして出たエラーを解消という様に段階を踏める
    • レベル
  • ベースラインファイルがある
    • 「〇〇より前に作成されたファイルはエラーが出ても無視します」的な事ができるっぽい
    • ベースライン

方法

  1. 下記コマンドを実行してlarastanをインストールする。

    composer require nunomaduro/larastan:^2.0 --dev
    
  2. アプリケーションルート(アプリ名ディレクトリ)にphpstan.neonファイルを新規作成して追加する。(一旦Stanのレベルは5とした。)

    アプリ名ディレクトリ/phpstan.neon
    includes:
        - ./vendor/nunomaduro/larastan/extension.neon
    
    parameters:
    
        paths:
            - app/
    
        # Level 9 is the highest level
        level: 5
    
  3. アプリ名ディレクトリ(Docker使っている場合はDockerコンテナに入り)に移動して下記コマンドを実行すると静的解析を実行する事ができる。

    ./vendor/bin/phpstan analyse
    

参考文献

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0