Bladestan + Larastan - Custom Artisan command error
johnbacon opened this issue · comments
I have created a reproducer repository for you to try + to exemplify the error. Everything is stock Laravel 10.18 except for:
- composer.json
- Requiring Bladestan and Larastan.
- phpstan.neon
- Including Bladestan and Larastan.
- DusterCodeFix.php
- The custom command that shows the error.
I've commented on the files to be explanatory. When running ./vendor/bin/phpstan analyze ./app/Console/Commands/DusterCodeFix.php -v
with both extensions enabled, the following error is produced:
-- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Error
-- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Internal error: Internal error: Target [Illuminate\Database\Migrations\MigrationRepositoryInterface] is not instantiable while building [Illuminate\Database\Console\Migrations\MigrateCommand,
Illuminate\Database\Migrations\Migrator]. in file /e/server/bladestan-error/app/Console/Commands/DusterCodeFix.php
Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:
#0 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(921): Illuminate\Container\Container->notInstantiable()
#1 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\Container\Container->build()
#2 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(933): Illuminate\Container\Container->resolve()
#3 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\Foundation\Application->resolve()
#4 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(918): Illuminate\Container\Container->make()
#5 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(1066): Illuminate\Foundation\Application->make()
#6 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(982): Illuminate\Container\Container->resolveClass()
#7 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(943): Illuminate\Container\Container->resolveDependencies()
#8 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\Container\Container->build()
#9 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(933): Illuminate\Container\Container->resolve()
#10 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\Foundation\Application->resolve()
#11 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(918): Illuminate\Container\Container->make()
#12 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(1066): Illuminate\Foundation\Application->make()
#13 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(982): Illuminate\Container\Container->resolveClass()
#14 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(943): Illuminate\Container\Container->resolveDependencies()
#15 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\Container\Container->build()
#16 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(933): Illuminate\Container\Container->resolve()
#17 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\Foundation\Application->resolve()
#18 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(918): Illuminate\Container\Container->make()
#19 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Console/Application.php(249): Illuminate\Foundation\Application->make()
#20 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Console/Application.php(263): Illuminate\Console\Application->resolve()
#21 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php(404): Illuminate\Console\Application->resolveCommands()
#22 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Console/Application.php(130): Illuminate\Support\ServiceProvider->Illuminate\Support\{closure}()
#23 /e/server/bladestan-error/vendor/laravel/framework/src/Illuminate/Console/Application.php(77): Illuminate\Console\Application->bootstrap()
#24 /e/server/bladestan-error/vendor/nunomaduro/larastan/src/Internal/ConsoleApplicationResolver.php(50): Illuminate\Console\Application->__construct()
#25 /e/server/bladestan-error/vendor/nunomaduro/larastan/src/Internal/ConsoleApplicationResolver.php(26): NunoMaduro\Larastan\Internal\ConsoleApplicationResolver->getApplication()
#26 /e/server/bladestan-error/vendor/nunomaduro/larastan/src/ReturnTypes/ConsoleCommand/ArgumentDynamicReturnTypeExtension.php(69):
NunoMaduro\Larastan\Internal\ConsoleApplicationResolver->findCommands()
#27 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3481):
NunoMaduro\Larastan\ReturnTypes\ConsoleCommand\ArgumentDynamicReturnTypeExtension->getTypeFromMethodCall()
#28 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1376): PHPStan\Analyser\MutatingScope->methodCallReturnType()
#29 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1382): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()
#30 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(564): PHPStan\Analyser\MutatingScope->resolveType()
#31 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(761): PHPStan\Analyser\MutatingScope->getType()
#32 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(564): PHPStan\Analyser\MutatingScope->resolveType()
#33 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1545): PHPStan\Analyser\MutatingScope->getType()
#34 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(598): PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr()
#35 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#36 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(557): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#37 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#38 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(640): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#39 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#40 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(612): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#41 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(353): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#42 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(166): PHPStan\Analyser\NodeScopeResolver->processNodes()
#43 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(130): PHPStan\Analyser\FileAnalyser->analyseFile()
#44 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}()
#45 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_7c49c944c\Evenement\EventEmitter->emit()
#46 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_7c49c944c\Clue\React\NDJson\Decoder->handleData()
#47 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_7c49c944c\Evenement\EventEmitter->emit()
#48 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):
_PHPStan_7c49c944c\React\Stream\Util::_PHPStan_7c49c944c\React\Stream\{closure}()
#49 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_7c49c944c\Evenement\EventEmitter->emit()
#50 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_7c49c944c\React\Stream\DuplexResourceStream->handleData()
#51 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173):
_PHPStan_7c49c944c\React\EventLoop\StreamSelectLoop->waitForStreamActivity()
#52 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(96): _PHPStan_7c49c944c\React\EventLoop\StreamSelectLoop->run()
#53 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()
#54 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_7c49c944c\Symfony\Component\Console\Command\Command->run()
#55 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_7c49c944c\Symfony\Component\Console\Application->doRunCommand()
#56 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_7c49c944c\Symfony\Component\Console\Application->doRun()
#57 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_7c49c944c\Symfony\Component\Console\Application->run()
#58 phar:///e/server/bladestan-error/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_7c49c944c\{closure}()
#59 /e/server/bladestan-error/vendor/phpstan/phpstan/phpstan(8): require('...')
#60 /e/server/bladestan-error/vendor/bin/phpstan(120): include('...')
#61 {main}
Child process error (exit code 1):
-- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In our production repo, the error is different since we have different packages installed:
Internal error: Internal error: Target class [command.debugbar.clear] does not exist. in file /e/server/private-repo/app/Console/Commands/DusterCodeFix.php
I'd love to have a way to specify Bladestan (and not PHPStan as a whole) ignore specific files and directories. Or to see this fixed generally!
Please let me know if this is ultimately a Larastan issue or if I can help in any way.
I belive this is an issue that started appearing after Larastan 2.5.2, so if you lock it at 2.5.1 it should be able to run with out errors.
Larastan 2.5.2 was released ~four months back -- but does that mean you feel this is actually an issue on Larastan's end?
I haven't had time to really investigate exactly what is causing the conflict, but since Bladestan is not as mature as Larastan and we already know that there are some conflicts with running both I'm more inclined to think the issue is with Bladestan.
Locking to 2.5.1 is just my suggested workaround until the issue is identified and addressed properly.
@johnbacon could you test with latest dev-main
to see if the issue is now resolved.
That did the trick! Excellent, thank you!