Closed AJenbo closed 1 year ago
Adding the following to my config/app.php
resolves the issue:
$config = [
'aliases' => [
'config' => Illuminate\Config\Repository::class,
The alias would normally be registered by Illuminate\Foundation\Application::registerCoreContainerAliases()
, I'm wondering if Larastan or something else is somehow sidestepping this.
I tried that suggestion @AJenbo and it did in fact remove the posted error. However I do end up with a different error as a result:
Uncaught Error: Call to a member function driver() on null in /app/vendor/nunomaduro/larastan/src/Methods/Pipes/Managers.php:38
#0 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): NunoMaduro\Larastan\Methods\Pipes\Managers->handle(Object(NunoMaduro\Larastan\Methods\Passable), Object(Closure))
#1 /app/vendor/nunomaduro/larastan/src/Methods/Pipes/Facades.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(NunoMaduro\Larastan\Methods\Passable))
#2 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): NunoMaduro\Larastan\Methods\Pipes\Facades->handle(Object(NunoMaduro\Larastan\Methods\Passable), Object(Closure))
#3 /app/vendor/nunomaduro/larastan/src/Methods/Pipes/Contracts.php(36): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(NunoMaduro\Larastan\Methods\Passable))
#4 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): NunoMaduro\Larastan\Methods\Pipes\Contracts->handle(Object(NunoMaduro\Larastan\Methods\Passable), Object(Closure))
#5 /app/vendor/nunomaduro/larastan/src/Methods/Pipes/SelfClass.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(NunoMaduro\Larastan\Methods\Passable))
#6 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): NunoMaduro\Larastan\Methods\Pipes\SelfClass->handle(Object(NunoMaduro\Larastan\Methods\Passable), Object(Closure))
#7 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(NunoMaduro\Larastan\Methods\Passable))
#8 /app/vendor/nunomaduro/larastan/src/Methods/Passable.php(187): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#9 /app/vendor/nunomaduro/larastan/src/Methods/Pipes/Facades.php(34): NunoMaduro\Larastan\Methods\Passable->sendToPipeline('Illuminate\\Sess...', true)
#10 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): NunoMaduro\Larastan\Methods\Pipes\Facades->handle(Object(NunoMaduro\Larastan\Methods\Passable), Object(Closure))
#11 /app/vendor/nunomaduro/larastan/src/Methods/Pipes/Contracts.php(36): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(NunoMaduro\Larastan\Methods\Passable))
#12 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): NunoMaduro\Larastan\Methods\Pipes\Contracts->handle(Object(NunoMaduro\Larastan\Methods\Passable), Object(Closure))
#13 /app/vendor/nunomaduro/larastan/src/Methods/Pipes/SelfClass.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(NunoMaduro\Larastan\Methods\Passable))
#14 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): NunoMaduro\Larastan\Methods\Pipes\SelfClass->handle(Object(NunoMaduro\Larastan\Methods\Passable), Object(Closure))
#15 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(NunoMaduro\Larastan\Methods\Passable))
#16 /app/vendor/nunomaduro/larastan/src/Methods/Kernel.php(66): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 /app/vendor/nunomaduro/larastan/src/Methods/Extension.php(42): NunoMaduro\Larastan\Methods\Kernel->handle(Object(PHPStan\Reflection\ClassReflection), 'put')
#18 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(429): NunoMaduro\Larastan\Methods\Extension->hasMethod(Object(PHPStan\Reflection\ClassReflection), 'put')
#19 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php(553): PHPStan\Reflection\ClassReflection->hasMethod('put')
#20 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods/CallToStaticMethodStatementWithoutSideEffectsRule.php(69): PHPStan\Type\ObjectType->hasMethod('put')
#21 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(106): PHPStan\Rules\Methods\CallToStaticMethodStatementWithoutSideEffectsRule->processNode(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope))
#22 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(98): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope))
#23 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(508): PHPStan\Node\ClassStatementsGatherer->__invoke(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope))
#24 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(417): PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope))
#25 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#26 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(648): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\If_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#27 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\If_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#28 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1054): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\TryCatch), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#29 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\TryCatch), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#30 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(523): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#31 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#32 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(601): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#33 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(362): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#34 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(573): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#35 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(331): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#36 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(175): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#37 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(72): PHPStan\Analyser\FileAnalyser->analyseFile('/app/app/Http/A...', Array, Object(PHPStan\Rules\LazyRegistry), Object(PHPStan\Collectors\Registry), NULL)
#38 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(62): PHPStan\Analyser\Analyser->analyse(Array, Object(Closure), NULL, true, Array)
#39 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(209): PHPStan\Command\AnalyserRunner->runAnalyser(Array, Array, Object(Closure), NULL, true, true, '/app/phpstan.ne...', Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Input\ArgvInput))
#40 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(102): PHPStan\Command\AnalyseApplication->runAnalyser(Array, Array, true, '/app/phpstan.ne...', Object(PHPStan\Command\Symfony\SymfonyOutput), Object(PHPStan\Command\Symfony\SymfonyOutput), Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Input\ArgvInput))
#41 phar:///app/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(190): PHPStan\Command\AnalyseApplication->analyse(Array, false, Object(PHPStan\Command\Symfony\SymfonyOutput), Object(PHPStan\Command\Symfony\SymfonyOutput), false, true, '/app/phpstan.ne...', Array, Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Input\ArgvInput))
#42 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\AnalyseCommand->execute(Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Output\ConsoleOutput))
#43 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_cbfb23d84\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Output\ConsoleOutput))
#44 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_cbfb23d84\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\AnalyseCommand), Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Output\ConsoleOutput))
#45 phar:///app/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_cbfb23d84\Symfony\Component\Console\Application->doRun(Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_cbfb23d84\Symfony\Component\Console\Output\ConsoleOutput))
#46 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_cbfb23d84\Symfony\Component\Console\Application->run()
#47 phar:///app/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_cbfb23d84\{closure}()
#48 /app/vendor/phpstan/phpstan/phpstan(8): require('phar:///app/ven...')
#49 /app/vendor/bin/phpstan(120): include('/app/vendor/php...')
#50 {main}
I'm guessing it has something to do with notification channels based on the file referenced in the analysis error output, but unfortunately I don't have time to dig in further at the moment.
I had a similar issue with code using session()->with(), the solution there for me was switching to $request->session()->now().
@Firehed could you check if the latest dev-main
solves all the conflicts you where having with the two extension?
I closed the issue since I was able to verify that things are now working correctly on the two project I have access to where this was an issue.
@AJenbo I no longer get the previous crashes, though we've significantly decoupled our app from Laravel since my previous comment so I have no good way of knowing if it's due to your change or other something else.
I am seeing that it's failing to detect an undefined variable in a mail template (which prompted me to try the extension in the first place) but that's almost certainly unrelated to this specific change.
I am seeing that it's failing to detect an undefined variable in a mail template
As I remember it currently not all methods of invoking email templates are analyzed. Could you post a short snipit of how you set the template, then I can change it in to a test for the case and maybe add support for it.
Sure. This is inside notification classes:
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class Whatever extends Notification
{
// ...
public function toMail($notifiable): MailMessage
{
return (new MailMessage())->view('my-view-name', [
'var1' => 'value1',
// ...
])->subject('not relevant');
}
}
The view template in question tried to use a key that wasn't provided via the data array (oops!) which turned into a runtime error.
Thanks for looking into it!
As a start I created a new issue for this: https://github.com/TomasVotruba/bladestan/issues/77
This appears to be a bad interaction between bladestan, larastan and the given project. When ever an instance of
Spatie\Permission\Models\Role
is used i get the below stack trace.This may well be related to #29
Drilling down to it we can see that
getTable()
on the model callsconfig()
for which Laravel's container will try to resolve theIlluminate\Config\Repository
class via the aliasconfig
, probably because ofIlluminate\Support\Facades\Config
.Disabeling Larastan will resolve this, but that is obviously not a viable option.