これはなに
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.neon
の ignoreErrors
に以下を記述
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
めでたしめでたし