biati-digital / nova-php-cs-fixer

Nova php-cs-fixer extension with HTML support
10 stars 2 forks source link

Indentation not supported in Blade @php blocks. #9

Closed Elwood-P closed 3 years ago

Elwood-P commented 3 years ago

Indentation not supported in Blade @php blocks:

@php
  $blocks = parse_blocks( get_the_content() );
  foreach ( $blocks as $block ) {
    if ( 'acf/feature' !== $block['blockName'] ) {
      echo render_block( $block );
    }
  }
@endphp

Changes to:

@php
$blocks = parse_blocks( get_the_content() );
foreach ( $blocks as $block ) {
if ( 'acf/feature' !== $block['blockName'] ) {
echo render_block( $block );
}
}
@endphp
biati-digital commented 3 years ago

Thank's for letting me know, I've not used blade yet so can you let me know if those blocks contain only PHP or can they contain HTML or some other blade tags?

biati-digital commented 3 years ago

I've been reading about blade, isn't it the point of blade to separate the logic from the template? is there a reason to do it the way you do it? also blade offers a foreach tag, does the foreach tag does not work the same?

@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach

I'm asking because, it will be difficult to format those PHP blocks, currently I'm really busy so I'm not gonna be able to take a look at this, as soon as I've some time I'll review this again.

biati-digital commented 3 years ago

I've submitted an update 2.0.5, although it won't format the inner PHP code it will not modify the indentation, basically it should leave the code exactly the same way you add it.

Hopefully you'll be able to keep working without worring about the formatter messing up those @php blocks.

Elwood-P commented 3 years ago

Thank you, not amending the indentation is definitely better.

You are right this block of logic definitely is not best practice to have in a blade template! It will be extracted out later. I'm pretty new to blade also so its easier for me to build something out quickly and then tidy it up into the right places. Still sometimes I think some php is necessary.