Running the php artisan model:typer command results in the following error if your project has an abstract model class:
TypeError
FumeApp\ModelTyper\Actions\RunModelShowCommand::__invoke(): Return value must be of type array, null returned
at vendor/fumeapp/modeltyper/src/Actions/RunModelShowCommand.php:30
26▕ if ($exitCode !== 0) {
27▕ throw new Exception('You may need to install the doctrine/dbal package to use this command.');
28▕ }
29▕
➜ 30▕ return json_decode(Artisan::output(), true);
31▕ }
32▕ }
33▕
[2m+20 vendor frames [22m
21 artisan:35
Illuminate\Foundation\Console\Kernel::handle()
I ran into this issue when I added an abstract class called BaseModel that extended the eloquent model.
Suggestions:
1) Do not attempt to write abstract classes
2) Create a validation check for the show:model command output in RunShowModelCommand action to avoid confusing error messages when artisan fails.
Point number 2 is also relevant for the future testing, since Artisan::output() returns empty string in Laravel test environment unless you have set the following property in your test case class.
public $mockConsoleOutput = false;
We could do a validity check along the lines of
$output = json_decode(Artisan::output(), true);
if (empty($output)) {
$msg = "Could not resolve types for model '$model', Artisan::output() is empty.";
$msg .= PHP_EOL . 'If you are running tests, make sure to set {public $mockConsoleOutput = false;}';
throw new \Exception($msg);
}
Running the
php artisan model:typer
command results in the following error if your project has an abstract model class:I ran into this issue when I added an abstract class called
BaseModel
that extended the eloquent model.Suggestions: 1) Do not attempt to write abstract classes 2) Create a validation check for the
show:model
command output inRunShowModelCommand
action to avoid confusing error messages when artisan fails.Point number 2 is also relevant for the future testing, since
Artisan::output()
returns empty string in Laravel test environment unless you have set the following property in your test case class.We could do a validity check along the lines of