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

Issue:
Error: Missing block "end" 
## Bug report

### Description

File is not fixed, becouse errors reported during fixing.

### Runtime version

PHP CS Fixer 3.14.3 Oliva by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.8

### Used command

php-cs-fixer fix test.php --using-cache no --allow-risky=yes -vvv

### Configuration file

```php
<?php

declare(strict_types=1);

use PhpCsFixer\Config;

return (new Config())
    ->setRules([
        '@PSR12'                       => true,
        '@Symfony:risky'               => true,
        'array_indentation'            => true,
        'blank_line_after_opening_tag' => true,
        'array_syntax'                 => ['syntax' => 'short'],
        'combine_consecutive_unsets'   => true,
        'class_attributes_separation'  => ['elements' => [
            'method'       => 'one',
            'property'     => 'only_if_meta',
            'const'        => 'only_if_meta',
            'trait_import' => 'one',
        ],
        ],
        'multiline_whitespace_before_semicolons' => false,
        'single_quote'                           => true,
        'binary_operator_spaces'                 => [
            'operators' => [
                '=>' => 'align_single_space_minimal',
            ],
        ],
        'braces' => [
            'allow_single_line_closure' => true,
        ],
        'concat_space'                       => ['spacing' => 'one'],
        'declare_equal_normalize'            => true,
        'function_typehint_space'            => true,
        'include'                            => true,
        'lowercase_cast'                     => true,
        'no_blank_lines_after_class_opening' => true,
        'no_blank_lines_after_phpdoc'        => true,
        'no_empty_comment'                   => true,
        'no_empty_phpdoc'                    => true,
        'no_empty_statement'                 => true,
        'no_extra_blank_lines'               => [
            'tokens' => [
                'curly_brace_block',
                'extra',
                'parenthesis_brace_block',
                'square_brace_block',
                'throw',
                'use',
                'break',
                'continue',
                'return',
                'throw',
            ],
        ],
        'no_leading_namespace_whitespace'             => true,
        'no_mixed_echo_print'                         => ['use' => 'echo'],
        'no_multiline_whitespace_around_double_arrow' => true,
        'no_short_bool_cast'                          => true,
        'no_singleline_whitespace_before_semicolons'  => true,
        'no_spaces_around_offset'                     => true,
        'no_trailing_comma_in_singleline'             => true,
        'no_unneeded_control_parentheses'             => true,
        'no_unused_imports'                           => true,
        'no_whitespace_before_comma_in_array'         => true,
        'no_whitespace_in_blank_line'                 => true,
        'object_operator_without_whitespace'          => true,
        'phpdoc_align'                                => true,
        'phpdoc_annotation_without_dot'               => true,
        'phpdoc_indent'                               => true,
        'phpdoc_no_alias_tag'                         => true,
        'phpdoc_scalar'                               => true,
        'phpdoc_separation'                           => true,
        'phpdoc_single_line_var_spacing'              => true,
        'phpdoc_to_comment'                           => true,
        'phpdoc_trim'                                 => true,
        'phpdoc_types'                                => true,
        'return_type_declaration'                     => true,
        'short_scalar_cast'                           => true,
        'single_blank_line_before_namespace'          => true,
        'single_class_element_per_statement'          => true,
        'space_after_semicolon'                       => true,
        'standardize_not_equals'                      => true,
        'ternary_operator_spaces'                     => true,
        'trim_array_spaces'                           => true,
        'unary_operator_spaces'                       => true,
        'whitespace_after_comma_in_array'             => true,
        'trailing_comma_in_multiline'                 => true,
    ]);
```
### Code snippet that reproduces the problem

input valid code:
  ```php
<?php

class test
{
    public function example(){ // example

    }
}
  ```
result should be something like:
  ```php
<?php

class test
{
    public function example() //example
    {
    }
}
  ```

error:   [UnexpectedValueException]  Missing block "end". 





Discussion: note:
if there is no empty space after "{" Fixer will fix it correctly
this is fixed:
```  
    public function example(){//test
    }
```
fixed code:
```  
    public function example()//test
    {
    }
```
return error:
```
    public function example(){  //test
    }
```



Fix (patch):
diff --git a/src/Fixer/Basic/CurlyBracesPositionFixer.php b/src/Fixer/Basic/CurlyBracesPositionFixer.php
index bcd58fe9dfb..42b343dbbd7 100644
--- a/src/Fixer/Basic/CurlyBracesPositionFixer.php
+++ b/src/Fixer/Basic/CurlyBracesPositionFixer.php
@@ -312,7 +312,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
                         } else {
                             $tokens->clearAt($openBraceIndex + 1);
                         }
-                    } else {
+                    } elseif ($tokens[$openBraceIndex - 1]->isWhitespace()) {
                         $tokens->clearAt($openBraceIndex - 1);
                     }
                 }