Repository: PHP-CS-Fixer/PHP-CS-Fixer (php)

Issue:
`single_space_around_construct` ignored for alternative syntax
### Problem description

The `single_space_around_construct` rule does not apply to `if` statements with [alternative syntax](https://www.php.net/manual/en/control-structures.alternative-syntax.php). 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

- [X] I have verified if this problem was already reported
- [X] I am familiar with ["Feature or bug?"](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/feature-or-bug.rst)

Pull request:
fix: `SingleSpaceAroundConstructFixer` - handle alternative syntax
Fixes #8316.

Patch:
diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixer.php
index c76ef2931..04ae646dd 100644
--- a/src/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixer.php
+++ b/src/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixer.php
@@ -237,7 +237,7 @@ public function isCandidate(Tokens $tokens): bool
             ...array_values($this->fixTokenMapFollowedByASingleSpace),
         ];
 
-        return $tokens->isAnyTokenKindsFound($tokenKinds) && !$tokens->hasAlternativeSyntax();
+        return $tokens->isAnyTokenKindsFound($tokenKinds);
     }
 
     protected function configurePostNormalisation(): void
@@ -333,7 +333,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
 
             $whitespaceTokenIndex = $index + 1;
 
-            if ($tokens[$whitespaceTokenIndex]->equalsAny([',', ';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE], [CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE]])) {
+            if ($tokens[$whitespaceTokenIndex]->equalsAny([',', ':', ';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE], [CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE]])) {
                 continue;
             }
 


Test patch:
diff --git a/tests/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixerTest.php b/tests/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixerTest.php
index a80ad8684..e0d97df87 100644
--- a/tests/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixerTest.php
+++ b/tests/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixerTest.php
@@ -1243,6 +1243,28 @@ public static function provideFixWithElseIfCases(): iterable
             '<?php if (true) {} elseif /* foo */(false) {}',
             '<?php if (true) {} elseif/* foo */(false) {}',
         ];
+
+        yield [
+            '<?php if (true): elseif (false): endif;',
+            '<?php if (true): elseif(false): endif;',
+        ];
+
+        yield [
+            '<?php if (true): elseif (false): endif;',
+            '<?php if (true): elseif  (false): endif;',
+        ];
+
+        yield [
+            '<?php if (true): elseif (false): endif;',
+            '<?php if (true): elseif
+
+(false): endif;',
+        ];
+
+        yield [
+            '<?php if (true): elseif /* foo */(false): endif;',
+            '<?php if (true): elseif/* foo */(false): endif;',
+        ];
     }
 
     /**
@@ -1910,6 +1932,32 @@ public static function provideFixWithIfCases(): iterable
             '<?php if /* foo */($foo === $bar) {}',
             '<?php if/* foo */($foo === $bar) {}',
         ];
+
+        yield [
+            '<?php if ($foo === $bar): endif;',
+            '<?php if($foo === $bar): endif;',
+        ];
+
+        yield [
+            '<?php if ($foo === $bar): endif;',
+            '<?php if  ($foo === $bar): endif;',
+        ];
+
+        yield [
+            '<?php if ($foo === $bar): endif;',
+            '<?php if
+
+($foo === $bar): endif;',
+        ];
+
+        yield [
+            '<?php if /* foo */($foo === $bar): endif;',
+            '<?php if/* foo */($foo === $bar): endif;',
+        ];
+
+        yield [
+            '<?php if (true): else: endif;',
+        ];
     }
 
     /**