Closed montchr closed 1 month ago
This is most often cause by non-terminated lined PHP statements in the template. See https://github.com/TomasVotruba/bladestan/issues/57 for details. When you get a syntax error like this the line number is in relation to the compiled php, not the blade template, so not very useful.
If you post the full template I can maybe spot the issue, unless it's in an included component.
Here's the full template, with a couple changes from what I posted earlier (still the same results):
@php
$itemComponent = sprintf('entity-list.%s.item', $layout->value);
@endphp
<section {{ $attributes->class(['entity-list', 'flex flex-col']) }}>
@if ($title)
<x-section-title class='entity-list__title'>
{{ $title }}
</x-section-title>
@endif
<div @class([
'entity-list__items',
sprintf('is-layout-%s', $layout->value),
'flex',
'gap-4' => $layout === \App\View\Support\EntityListLayout::GRID,
'flex-col gap-y-8' =>
$layout === \App\View\Support\EntityListLayout::STREAM,
])>
@foreach ($entities as $entity)
<div class="gap-4">
<x-dynamic-component
:component="$itemComponent"
:$entity
/>
</div>
@endforeach
</div>
</section>
I've looked through the entire project for non-terminated statements in any template, but found none. I assume that the standalone @php()
directive is exempt?
I assume that the standalone
@php()
directive is exempt?
No, that is exactly where this issue normally arises.
They are normally allowed in PHP but to analyze all of the code Bladestan collects them all in to a single script.
Edit: I'm not seeing any issues in the file you posted.
Hmm… even after eliminating @php()
entirely and verifying that each statement ends in a semicolon, I still get the same error.
Is there any way I could see more detailed output to trace the exact code output that causes the issue?
More ripgrep output, also double-checked in phpstorm in case my regex is bad:
❯ rg --multiline --multiline-dotall --glob 'resources/views/**/*.blade.php' '(@php.*?@endphp|@php\(.*?\))'
resources/views/layouts/sections/sidebar.blade.php
1:@php
2: dynamic_sidebar('sidebar-primary');
3:@endphp
resources/views/search.blade.php
2:@php use App\View\Support\EntityListLayout; @endphp
resources/views/partials/site-navigation.blade.php
35: @php
36: $isLinkable = $item->url !== '' && $item->url !== '#';
37: @endphp
192: @php
193: $isLinkable = $item->url !== '' && $item->url !== '#';
194: @endphp
resources/views/components/header/index.blade.php
1:@php
2: use App\Support\AspectRatio;
3: use App\Support\ImageSize;
4:@endphp
resources/views/page.blade.php
5: @php
6: the_post();
7: @endphp
resources/views/project/content.blade.php
1:@php
2: $reports = $project->reports();
3:@endphp
resources/views/components/entity-list/grid/item.blade.php
1:@php
2: use App\Support\AspectRatio;
3: use App\Support\ImageSize;
4:@endphp
resources/views/components/entity-list/wall/item.blade.php
1:@php use App\Support\ImageSize; @endphp
resources/views/components/entity-list/index.blade.php
1:@php
2: $itemComponent = sprintf('entity-list.%s.item', $layout->value);
3:@endphp
resources/views/topic/content.blade.php
1:@php use App\View\Support\EntityListLayout; @endphp
resources/views/front-page.blade.php
2:@php
3: $podcast_info_url = 'https://whyy.org/programs/stop-and-frisk-revisit-or-resist/';
4:@endphp
resources/views/components/entity-meta.blade.php
1:@php
2: $authorName = $author?->name();
3: $authorUrl = $author?->permalink();
4:
5: $displayFormat = get_option('date_format');
6: $published = $published->setTimezone(wp_timezone_string());
7:@endphp
resources/views/index.blade.php
16: @php
17: the_post();
18: @endphp
resources/views/components/entity-list/stream/item.blade.php
1:@php
2: use App\Support\AspectRatio;
3: use App\Support\ImageSize;
4:@endphp
I guess, also: do you know of any other problematic directives / bad practices to watch out for?
Edit: for example, might these attributes count as non-terminated statements?
<x-header
:title="$report->title()"
:image="$report->image()"
>
resources/views/topic/content.blade.php
@php use App\View\Support\EntityListLayout; @endphp
If this is a partial then you can't have use statements in it as it would result in things like:
@foreach([1])
@include('topic.content')
}
<?php
foreach ([1] as $a) {
use App\View\Support\EntityListLayout;
}
Thought I would have expected a different error if this was the issue. See https://github.com/TomasVotruba/bladestan/issues/58
I guess, also: do you know of any other problematic directives / bad practices to watch out for?
I documented the issues i found here: https://github.com/TomasVotruba/bladestan/issues/created_by/AJenbo
Edit: for example, might these attributes count as non-terminated statements?
<x-header :title="$report->title()" :image="$report->image()" >
I don't belive that would be an issue.
Is there any way I could see more detailed output to trace the exact code output that causes the issue?
I would suggest analyzing one file at a time, enable debugging and in BladeToPHPCompiler around line 160 echo out the compiled php so you can see what it is analyzing, then you can search for the faulty line in your templates locate the cause of the issue that way.
vendor/bin/phpstan analyze --error-format=blade --level 0 --debug app/Http/Controllers/HomeController.php
If that still doesn't give you a clear result then try removing 50% of the template until it parses succesfuld, the recover 25% and continue until you find the offending line. (bisecting the files)
Closing as the original author has not provided the needed info
Not sure exactly what's causing this error, but I can update the title if we come to a more specific description of the issue.
When I install bladestan and run phpstan for the first time, I see the following error:
There are no other reported errors.
From some of the other issue descriptions in this repo, I gather that the line number corresponds to the template, not the controller? I saw that removing a blank line in the template caused an equal change in line numbering in the error report (was L18, now is L17).
Here is the relevant context, including both the template and its corresponding
Component
class:Other notes:
EntityListLayout
is an enumEntityList.php
sprintf
s