-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should not happen...happens #92
Comments
Hi, it's hard to debug with out knowing the code that triggers this. Can you please provide an example of how your code calls the For reference this is where the analyzer dies:
If you can modify that to output the class of $rootViewNode->name that could also be helpful.
My best guess from looking at the stack trace is that the code looks something like this: <?php
namespace Eagle\File\Relation;
use App\Settings\Model\SomeSetting, but that's just a guess;
trait Something
{
public somthing()
{
new SomeSetting();
foreach () {
$thing = view();
}
}
} I took a look at https://github.com/eagle-metal, but it does not appear that the offending code is part of the publicly available repos. You can run |
@AJenbo, thanks for the response.
I completely understand, however, this was produced with I'm not even sure what file caused the error as the last filename on the list does not contain a |
It's hard to say, it could be interactions between other PHPStan plugins so it's not really easy to say without a test case. Hopefully you can work on narrowing down the code that triggers it. |
@AJenbo, here's a minimum example (although there could be other issues not represented here): <?php
namespace App\View\Components;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Messages extends Component
{
public function __construct(
public string $resourceRoute,
public array $messages = [],
public ?string $fileMorphAlias = null,
public bool $canCreateMessage = false,
) {
}
public function render(): View
{
return view('ems._components.messages');
}
} @php
use App\Mail\Models\Message;
@endphp
<div class="mr-6">
<span>
<x-button.success
class="text-sm"
x-show="selected_message?.type === {{ Js::from(Message::TYPE_OUTGOING) }}"
>
Resend message
</x-button.success>
</span>
<div class="mr-6">
@isset($additional_actions)
{{ $additional_actions }}
@endisset
</div>
</div> Note that if I remove the |
Could you try this: <?php
namespace App\View\Components;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Messages extends Component
{
public function __construct(
public string $resourceRoute,
public array $messages = [],
public ?string $fileMorphAlias = null,
public bool $canCreateMessage = false,
) {
}
public function render(): View
{
return $this->view('ems._components.messages', [
'resourceRoute' => $this->resourceRoute,
'messages' => $this->messages,
'fileMorphAlias' => $this->fileMorphAlias,
'canCreateMessage' => $this->canCreateMessage,
]);
}
} Bladestan isn't able to infer that the component and it's properties will be grabbed from the scope of the caller when calls happen inside a component. Also calling the member method gives it a slightly better context. |
Is the blade file you posted |
@AJenbo, no go... Here's the output of /var/www/app/View/Components/Messages.php
PhpParser\Node\Expr\MethodCall^ {#56669
#attributes: array:6 [
"startLine" => 123
"startTokenPos" => 789
"startFilePos" => 3609
"endLine" => 123
"endTokenPos" => 795
"endFilePos" => 3632
]
+var: PhpParser\Node\Expr\Variable^ {#56667
#attributes: array:6 [
"startLine" => 123
"startTokenPos" => 789
"startFilePos" => 3609
"endLine" => 123
"endTokenPos" => 789
"endFilePos" => 3613
]
+name: "this"
}
+name: PhpParser\Node\Expr\Variable^ {#56668
#attributes: array:6 [
"startLine" => 123
"startTokenPos" => 792
"startFilePos" => 3617
"endLine" => 123
"endTokenPos" => 792
"endFilePos" => 3629
]
+name: "relationship"
}
+args: []
} // vendor/tomasvotruba/bladestan/src/PhpParser/NodeVisitor/ViewFunctionArgumentsNodeVisitor.php:77 |
this is not relevant to the error, the template I posted has been trimmed down while still obtaining the error---you can just substitute a button element |
Here's another MRE: <?php
namespace App\View\Components\Maintenance\System;
use Eagle\Maintenance\Models\MaintenanceSystem;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\View\Component;
class DropdownTree extends Component
{
public function __construct(
/** @var Collection<int, MaintenanceSystem> */
public Collection $systems,
public bool $onlyActive = true,
public ?MaintenanceSystem $selectedSystem = null,
) {
}
public function render(): View
{
return view('ems.maintenance.system._components.dropdown-tree');
}
} <div>
</div> Note that I've removed the entire blade contents and the failure still occurs---it's not until I remove all the properties from the class that phpstan passes: <?php
namespace App\View\Components\Maintenance\System;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class DropdownTree extends Component
{
public function __construct(
) {
}
public function render(): View
{
return view('ems.maintenance.system._components.dropdown-tree');
}
} |
You don't need to @ me I'm active in the topic 🙂 |
Scratch that I have some components like that as well and they do cause any issues. |
Sorry but this is not enough to replicate the issue (I tried adding them to another repo and analyzing them). Like I mentioned it could be interactions between other PHPStan plugins you are using, or some other aspect of your repo.
Maybe the issue is with Swapping it for a ransom model gives me a |
Have you tried removing |
I've created an example repo here: https://github.com/calebdw/bladestan-errors I've narrowed the issue down to two completely unrelated things that don't cause the failure when either of them are missing---not sure why their combined presence causes the failure. You're right about the issue being on the model---specifically with the The two interactions are:
The MaintenanceSystem is a recursive model and therefore uses the laravel-adjacency-list package for the recursive relationships. The We also have a custom Files relation that can be added to a model through the public function restoreAllFiles(): void
{
foreach ($this->fileRelationships as $relationship) {
$loaded = $this->{$relationship}()->withTrashed()->get();
foreach ($loaded as $relation) {
$relation->restore();
}
}
} however, there are other methods in the same trait with similar access that don't give Bladestan any issues---Bladestan should not be trying to analyze these methods in the first place though. For some reason, Bladestan is trying to analyze the |
Hello!
I'm trying to install and use this extension but I'm getting several of the below errors when trying to run PHPStan (level 1) on my codebase:
Thanks!
The text was updated successfully, but these errors were encountered: