Skip to content

phpcbf breaks php opening and closing tags adding spaces #2083

@giorgosbotis

Description

@giorgosbotis

Bug Description

Using phpcbf on a .php file with many opening and closing php tags both inline and multiline breaks the file completely. The result has < ? php with the spaces and missing closing tags.

Minimal Code Snippet

The issue happens when running this command:

phpcbf --standard=Wordpress-Core myfile.php

... over a file containing this code:

<?php

if (have_rows('page_block')): ?>
  <?php while (have_rows('page_block')):
    the_row(); ?>
    <?php if (get_row_layout() == 'my_block'): ?>
      <?php include get_theme_file_path(
        'my_block.php'
      ); ?>               
    <?php endif; ?>
  <?php endwhile; ?>
<?php endif; ?>

The file was auto-fixed via phpcbf to:

<?php

if ( have_rows( 'page_block' ) ) : ?>
	<?php
	while ( have_rows( 'page_block' ) ) :
		the_row();
		?>
		<?php
		if ( get_row_layout() == 'my_block' ) :
			< ? php
			include get_theme_file_path(
				'my_block.php'
			);
			?>
					 
	<?php endif; ?>
	<?php endwhile; ?>
	<?php
endif;

... while I expected the code to be fixed to:

<?php

if ( have_rows( 'page_block' ) ) {
  while ( have_rows( 'page_block' ) ) {
    the_row();
    if ( get_row_layout() == 'my_block' ) {
      include get_theme_file_path('/theme_extra/theme_blocks/page/timer_suppliers_block.php');
    }
  }
}

Error Code

Custom ruleset

Environment

Question Answer
PHP version 8.0.19
PHP_CodeSniffer version 3.7.1
WPCS version dev
WPCS install type composer local
IDE (if relevant) -

Additional Context (optional)

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of WPCS.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions