LoginSignup
0
2

More than 1 year has passed since last update.

Larastan使ってるとControllerのメソッド戻り値未指定で怒られる has no return typehint specified

Last updated at Posted at 2021-07-14

これはなに

Larastan使ってlevelをMAXにするとControllerの戻り値が未設定で怒られる

Method App\Http\Controllers\ExampleController::index() has no return typehint specified.  

なのでそのエラーの解消法

ControllerのメソッドでViewを返すときの戻り値

Illuminate\View\View を返す

<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\View\View;

class ExampleController extends Controller
{
    /**
     * @return \Illuminate\View\View
     */
    public function index(): View
    {
        return view('example');
    }
}

そもそも戻り値必須を無視

phpstan.neonignoreErrors に以下を記述

includes:
    - ./vendor/nunomaduro/larastan/extension.neon
parameters:
    paths:
        - app/
        - database/
        - tests/
    level: max
    excludePaths:
        - ./*/*/FileToBeExcluded.php
    ignoreErrors:
        # has no return typehint を無視
        - '#Method [A-Za-z0-9\\]+::[A-Za-z0-9_]+\(\) has no return typehint specified#'
    checkMissingIterableValueType: false

めでたしめでたし

0
2
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
0
2