Larastan doesn't find some console commands, so it doesn't know `option()` types
Author: rudiedirkxCreated Apr 8, 2025Updated May 28, 2026
Labelsbug
- Larastan: 3.0.4
- Laravel: 11.35.1
- Phpstan: 2.1.3
Description
When I run analysis on a command, $this->option('institution') returns Laravel's default string|array|bool|null instead of Larastan's smart specific, because Larastan's console Application didn't load this command. It loads some custom/app commands, but not this one. Probably because this one is defined in the app kernel:
protected $commands = [
\App\Service\Import\ImportCoursesCommand::class,
// ... a few more
];and it's not in the app Commands/ folder (loaded through Kernel::commands(), which apparently does work!?). Commands loaded from specific service providers also work.
Why doesn't Larastan use Kernel logic to load commands?
If I hack Larastan's ConsoleApplicationResolver to add:
$this->application->resolveCommands([
\App\Service\Import\ImportCoursesCommand::class,
// ... a few more
]);in getApplication(), the commands are registered, the classes are detected, option() returns the right type.
Source: larastan/larastan