Incorrect @php block indentation of if/elseif/else statements
See original GitHub issueContext (Environment)
I’ve noticed incorrect indentation when using an if/elseif/else
statement inside a @php
block. The code inside the block still works fine, it’s just the else
ends up indented incorrectly.
Current Behavior
This is how the code ends up indented:
<td>
@php
if ($condition1) {
$var1 = '...';
$var2 = '...';
} elseif ($condition2) {
$var1 = '...';
$var2 = '...';
} else {
$var1 = '...';
$var2 = '...';
}
@endphp
<span>{{ $var1 . $var2 }}</span>
</td>
Expected Behavior
This is how I would expect the code to be indented:
<td>
@php
if ($condition1) {
$var1 = '...';
$var2 = '...';
} elseif ($condition2) {
$var1 = '...';
$var2 = '...';
} else {
$var1 = '...';
$var2 = '...';
}
@endphp
<span>{{ $var1 . $var2 }}</span>
</td>
Detailed Description
I’ve tried 1.4.19 and 1.4.20 and this indentation occurs in both versions.
Steps to Reproduce
See examples above.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Incorrect Indentation for if statements with else #1576 - GitHub
I am getting the following error for if ( is_customize_preview() ) : 11 | ERROR | [x] Line indented incorrectly; expected 0 tabs, ......
Read more >else - Manual - PHP
The else statement is only executed if the if expression evaluated to false , and if there were any elseif expressions - only...
Read more >javascript - PHP if else - proper use of "else" - Stack Overflow
When one condition evaluates true, the code in the block is executed and then the entire if-else construct is exited.
Read more >During if and else statements,what are the rules of indentation?
Indentations are used to denote a block of code. Basically, every time you end a line with a colon (:) the following line...
Read more >How To Write Conditional Statements in PHP - DigitalOcean
Next, it will take you through writing conditional statements in PHP, including the if , else , and elseif keywords.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed at https://github.com/shufo/blade-formatter/releases/tag/v1.26.16
@ziadoz Thanks! Reproduced in my environment. That is unexpected behaviour. I’ll look into it.