Skip to content

single_space_around_construct ignored for alternative syntax #8316

@timsmid

Description

@timsmid

Problem description

The single_space_around_construct rule does not apply to if statements with alternative syntax. If a file contains any alternative syntax, the single_space_around_construct rule is even skipped for the whole file.

Other rules seem to handle normal and alternative syntax equally. As far as I can tell the documentation of the single_space_around_construct rule does not exclude the alternative syntax. Therefor, this seems to be an unintentional bug.

I will open a PR with a possible fix in a few minutes.

Minimal reproducer

file.php:

<?php if(true): ?>
    A
<?php elseif(false): ?>
    B
<?php else: ?>
    C
<?php endif; ?>

Command:

source/vendor/bin/php-cs-fixer fix --rules=single_space_around_construct file.php

Expected contents of file.php (notice space after if and elseif):

<?php if (true): ?>
    A
<?php elseif (false): ?>
    B
<?php else: ?>
    C
<?php endif; ?>

However, contents of file.php are unchanged.

Fixer version

3.65.0

PHP version

8.3.7

How do you run Fixer?

Composer package

Contribution Checks

  • I have verified if this problem was already reported
  • I am familiar with "Feature or bug?"

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugstatus/to verifyissue needs to be confirmed or analysed to continue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions