Repository: PHP-CS-Fixer/PHP-CS-Fixer

Issue #3637: 'braces' with option 'position_after_functions_and_oop_constructs' = 'next' does not work for multi line methods
Created: 2018-03-27T08:54:06Z
When reporting an issue (bug) please provide the following information:
The PHP version you are using ($ php -v):
=> php 7.1.13
PHP CS Fixer version you are using ($ php-cs-fixer -V):
=> .PHP CS Fixer 2.10.0
The command you use to run PHP CS Fixer:
=> fix
The configuration file you are using, if any:
=>'braces' => [
                'allow_single_line_closure' => true,
                'position_after_anonymous_constructs' => 'same',
                'position_after_functions_and_oop_constructs' => 'next',
                'position_after_control_structures' => 'same',
            ],
If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

before running PHP CS Fixer (no changes):

=> private function __construct(
    argument 1,
    argument 2,
    argument 3,
    argument 4
) 
{
}

with unexpected changes applied when running PHP CS Fixer:

=> private function __construct(
    argument 1,
    argument 2,
    argument 3,
    argument 4
) {
}

with the changes you expected instead:

=> private function __construct(
    argument 1,
    argument 2,
    argument 3,
    argument 4
) 
{
}

Duplicate issue #4836: Braces rule doesn't behave correctly when method arguments are multilined at definition.
Created: 2020-02-21T14:39:40Z
Hey there! :)
Found something. When method arguments are put on separate lines (to preserve max line length), PHPCSFixer thinks it has to put back braces (the only applied rule to this file) back to the line above.
This applies to 4 differents (magic and regular) methods in the same class, among 50 other methods (this is a really big class that exceeds standards decent size). All other methods are not touched. The only difference between those 4 is that arguments are put on a separate line. Works if I put them back on one line.
The PHP version you are using ($ php -v):
PHP 7.2.23 (cli) (built: Sep 25 2019 08:52:42) ( NTS MSVC15 (Visual C++ 2017) x64 )
PHP CS Fixer version you are using ($ php-cs-fixer -V):
PHP CS Fixer 2.16.1
The command you use to run PHP CS Fixer:
"../phpcsfixer/vendor/bin/php-cs-fixer" fix --show-progress=dots --verbose
The configuration file you are using, if any:
/**
 * PHP-CS-Fixer requires this file to be PHP.
 *
 * It requires it to return an instance of PhpCsFixer\Config.
 * Which, in its turn, requires an instance of PhpCsFixer\Finder (Symfony\Finder).
 */

/**
 * This is your project named configuration, please update it so people see that in the console.
 */
define('PROJECT_NAME', 'TEST-1.0');
/**
 * This is your target version of PHPUnit can cause BC break if not set correctly.
 */
define('PHPUNIT_TARGET_VERSION', 'newest');

/**
 * Create a new PhpCsFixer\Finder (Symfony\Finder) instance
 *
 * @see https://symfony.com/doc/current/components/finder.html
 * @var PhpCsFixer\Finder
 */
$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
    ->in(__DIR__ . DIRECTORY_SEPARATOR . 'config')
    ->in(__DIR__ . DIRECTORY_SEPARATOR . 'public')
    ->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests');

/**
 * Return a series of stacked calls to properly determine the configuration at launch.
 *
 * @see PhpCsFixer\Config
 * @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/src/Config.php
 * @var PhpCsFixer\Config
 */
return (new PhpCsFixer\Config(PROJECT_NAME))
    // Choose which rules to be applied, this is a whitelist, so by default none are applied
    // unless you add a set of rules here, then disable some of them.
    ->setRules(
        [
            'align_multiline_comment'                          => ['comment_type' => 'all_multiline'],
            'array_indentation'                                => false,
            'array_syntax'                                     => ['syntax' => 'short'],
            'backtick_to_shell_exec'                           => true,
            'binary_operator_spaces'                           => [
                'align_double_arrow' => true,
                'align_equals'       => false
            ],
            'blank_line_after_namespace'                       => true,
            'blank_line_after_opening_tag'                     => true,
            'blank_line_before_statement'                      => ['statements' => [
                'break',
                'continue',
                'declare',
                'return',
                'throw',
                'try',
                'if',
                'for',
                'foreach',
                'while',
                'do',
                'switch']
            ],
            'braces'                                           => [
                'allow_single_line_closure'                   => false,
                'position_after_anonymous_constructs'         => 'same',
                'position_after_control_structures'           => 'same',
                'position_after_functions_and_oop_constructs' => 'next',
            ],
            'cast_spaces'                                      => ['space' => 'single'],
            'class_attributes_separation'                      => ['elements' => ['const', 'method', 'property']],
            'class_definition'                                 => [
                'multi_line_extends_each_single_line' => true,
                'single_item_single_line'             => true,
                'single_line'                         => true,
            ],
            'class_keyword_remove'                             => false,
            'combine_consecutive_issets'                       => true,
            'combine_consecutive_unsets'                       => true,
            'combine_nested_dirname'                           => true,
            'comment_to_phpdoc'                                => ['ignored_tags' => []],
            'compact_nullable_typehint'                        => true,
            'concat_space'                                     => ['spacing' => 'one'],
            'constant_case'                                    => ['case' => 'lower'],
            'date_time_immutable'                              => false,
            'declare_equal_normalize'                          => ['space' => 'single'],
            'declare_strict_types'                             => false,
            'dir_constant'                                     => true,
            'doctrine_annotation_array_assignment'             => ['operator' => '='],
            'doctrine_annotation_braces'                       => ['syntax' => 'without_braces'],
            'doctrine_annotation_indentation'                  => ['indent_mixed_lines' => true],
            'doctrine_annotation_spaces'                       => [],
            'elseif'                                           => true,
            'encoding'                                         => true,
            'ereg_to_preg'                                     => true,
            'error_suppression'                                => [
                'mute_deprecation_error'         => false,
                'noise_remaining_usages'         => true,
                'noise_remaining_usages_exclude' => [],
            ],
            'escape_implicit_backslashes'                      => [],
            'explicit_indirect_variable'                       => true,
            'explicit_string_variable'                         => true,
            'final_class'                                      => false,
            'final_internal_class'                             => ['annotation-white-list' => ['@internal']],
            'final_public_method_for_abstract_class'           => false,
            'final_static_access'                              => true,
            'fopen_flag_order'                                 => true,
            'fopen_flags'                                      => true,
            'full_opening_tag'                                 => true,
            'fully_qualified_strict_types'                     => true,
            'function_declaration'                             => ['closure_function_spacing' => 'none'],
            'function_to_constant'                             => [],
            'function_typehint_space'                          => true,
            'general_phpdoc_annotation_remove'                 => ['annotations' => ['author']],
            'global_namespace_import'                          => [],
            'heredoc_to_nowdoc'                                => true,
            'implode_call'                                     => true,
            'include'                                          => true,
            'increment_style'                                  => ['style' => 'pre'],
            'indentation_type'                                 => true,
            'is_null'                                          => ['use_yoda_style' => false],
            'line_ending'                                      => true,
            'linebreak_after_opening_tag'                      => true,
            'list_syntax'                                      => ['syntax' => 'short'],
            'logical_operators'                                => true,
            'lowercase_cast'                                   => true,
            'lowercase_keywords'                               => true,
            'lowercase_static_reference'                       => true,
            'magic_constant_casing'                            => true,
            'magic_method_casing'                              => true,
            'mb_str_functions'                                 => true,
            'method_argument_space'                            => [],
            'method_chaining_indentation'                      => true,
            'modernize_types_casting'                          => true,
            'multiline_comment_opening_closing'                => true,
            'multiline_whitespace_before_semicolons'           => [],
            'native_constant_invocation'                       => [],
            'native_function_casing'                           => true,
            'native_function_type_declaration_casing'          => true,
            'new_with_braces'                                  => true,
            'no_alias_functions'                               => [],
            'no_alternative_syntax'                            => true,
            'no_binary_string'                                 => true,
            'no_blank_lines_after_class_opening'               => true,
            'no_blank_lines_after_phpdoc'                      => true,
            'no_break_comment'                                 => [],
            'no_closing_tag'                                   => true,
            'no_empty_comment'                                 => true,
            'no_empty_phpdoc'                                  => true,
            'no_empty_statement'                               => true,
            'no_extra_blank_lines'                             => true,
            'no_homoglyph_names'                               => true,
            'no_leading_import_slash'                          => true,
            'no_leading_namespace_whitespace'                  => true,
            'no_mixed_echo_print'                              => ['use' => 'echo'],
            'no_multiline_whitespace_around_double_arrow'      => true,
            'no_null_property_initialization'                  => true,
            'no_php4_constructor'                              => true,
            'no_short_bool_cast'                               => true,
            'no_short_echo_tag'                                => true,
            'no_singleline_whitespace_before_semicolons'       => true,
            'no_spaces_after_function_name'                    => true,
            'no_spaces_around_offset'                          => ['positions' => ['inside', 'outside']],
            'no_spaces_inside_parenthesis'                     => true,
            'no_superfluous_elseif'                            => true,
            'no_superfluous_phpdoc_tags'                       => [
                'allow_mixed'         => true,
                'allow_unused_params' => true,
                'remove_inheritdoc'   => false,
            ],
            'no_trailing_comma_in_list_call'                   => true,
            'no_trailing_comma_in_singleline_array'            => true,
            'no_trailing_whitespace'                           => true,
            'no_trailing_whitespace_in_comment'                => true,
            'no_unneeded_control_parentheses'                  => [],
            'no_unneeded_curly_braces'                         => true,
            'no_unneeded_final_method'                         => true,
            'no_unreachable_default_argument_value'            => true,
            'no_unset_cast'                                    => true,
            'no_unset_on_property'                             => true,
            'no_unused_imports'                                => true,
            'no_useless_else'                                  => true,
            'no_useless_return'                                => true,
            'no_whitespace_before_comma_in_array'              => [],
            'no_whitespace_in_blank_line'                      => true,
            'non_printable_character'                          => [],
            'normalize_index_brace'                            => true,
            'not_operator_with_space'                          => false,
            'not_operator_with_successor_space'                => false,
            'nullable_type_declaration_for_default_null_value' => [],
            'object_operator_without_whitespace'               => true,
            'ordered_class_elements'                           => ['sortAlgorithm' => 'alpha'],
            'ordered_imports'                                  => ['sortAlgorithm' => 'alpha'],
            'ordered_interfaces'                               => [],
            'php_unit_construct'                               => [],
            'php_unit_dedicate_assert'                         => ['target' => PHPUNIT_TARGET_VERSION],
            'php_unit_dedicate_assert_internal_type'           => ['target' => PHPUNIT_TARGET_VERSION],
            'php_unit_expectation'                             => ['target' => PHPUNIT_TARGET_VERSION],
            'php_unit_fqcn_annotation'                         => true,
            'php_unit_internal_class'                          => [],
            'php_unit_method_casing'                           => [],
            'php_unit_mock'                                    => ['target' => PHPUNIT_TARGET_VERSION],
            'php_unit_mock_short_will_return'                  => true,
            'php_unit_namespaced'                              => ['target' => PHPUNIT_TARGET_VERSION],
            'php_unit_no_expectation_annotation'               => ['target' => PHPUNIT_TARGET_VERSION],
            'php_unit_ordered_covers'                          => true,
            'php_unit_set_up_tear_down_visibility'             => true,
            'php_unit_size_class'                              => true,
            'php_unit_strict'                                  => [],
            'php_unit_test_annotation'                         => [],
            'php_unit_test_case_static_method_calls'           => [],
            'php_unit_test_class_requires_covers'              => [],
            'phpdoc_add_missing_param_annotation'              => [],
            'phpdoc_align'                                     => ['align' => 'left'],
            'phpdoc_annotation_without_dot'                    => true,
            'phpdoc_indent'                                    => true,
            'phpdoc_inline_tag'                                => true,
            'phpdoc_line_span'                                 => [
                'const'    => 'single',
                'method'   => 'multi',
                'property' => 'single',
            ],
            'phpdoc_no_access'                                 => true,
            'phpdoc_no_alias_tag'                              => [],
            'phpdoc_no_empty_return'                           => false,
            'phpdoc_no_package'                                => true,
            'phpdoc_no_useless_inheritdoc'                     => true,
            'phpdoc_order'                                     => true,
            'phpdoc_return_self_reference'                     => [],
            'phpdoc_scalar'                                    => [],
            'phpdoc_separation'                                => true,
            'phpdoc_single_line_var_spacing'                   => true,
            'phpdoc_summary'                                   => true,
            'phpdoc_to_comment'                                => true,
            'phpdoc_trim'                                      => true,
            'phpdoc_trim_consecutive_blank_line_separation'    => true,
            'phpdoc_types'                                     => [],
            'phpdoc_types_order'                               => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'alpha'],
            'phpdoc_var_annotation_correct_order'              => true,
            'phpdoc_var_without_name'                          => false,
            'pow_to_exponentiation'                            => true,
            'protected_to_private'                             => true,
            'psr0'                                             => [],
            'psr4'                                             => true,
            'random_api_migration'                             => [],
            'return_assignment'                                => true,
            'return_type_declaration'                          => [],
            'self_accessor'                                    => true,
            'self_static_accessor'                             => true,
            'semicolon_after_instruction'                      => true,
            'set_type_to_cast'                                 => true,
            'short_scalar_cast'                                => true,
            'simple_to_complex_string_variable'                => true,
            'simplified_null_return'                           => true,
            'single_blank_line_at_eof'                         => true,
            'single_blank_line_before_namespace'               => true,
            'single_class_element_per_statement'               => [],
            'single_import_per_statement'                      => true,
            'single_line_after_imports'                        => true,
            'single_line_comment_style'                        => [],
            'single_line_throw'                                => true,
            'single_quote'                                     => ['strings_containing_single_quote_chars' => true],
            'single_trait_insert_per_statement'                => true,
            'space_after_semicolon'                            => [],
            'standardize_increment'                            => true,
            'standardize_not_equals'                           => true,
            'static_lambda'                                    => true,
            'strict_comparison'                                => true,
            'strict_param'                                     => true,
            'string_line_ending'                               => true,
            'switch_case_semicolon_to_colon'                   => true,
            'switch_case_space'                                => true,
            'ternary_operator_spaces'                          => true,
            'ternary_to_null_coalescing'                       => true,
            'trailing_comma_in_multiline_array'                => [],
            'trim_array_spaces'                                => true,
            'unary_operator_spaces'                            => true,
            'visibility_required'                              => [],
            'whitespace_after_comma_in_array'                  => true,
            'yoda_style'                                       => [
                'always_move_variable' => false,
                'equal'                => true,
                'identical'            => false,
                'less_and_greater'     => false,
            ]
        ]
    )
    // 4 spaces is the default value here, but overridden for demo purposes :)
    ->setIndent('    ')
    // Default value here, but overridden for demo purposes :)
    ->setLineEnding("\n")
    // Allow risky changes to the code instead of skipping them
    ->setRiskyAllowed(true)
    // Bind the above finder to this configuration
    ->setFinder($finder);
If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

before running PHP CS Fixer (no changes):

    /**
     * constructor.
     */
    public function __construct(
        Type $argument1,
        Type $argument2,
        Type $argument3,
    )
    {
        $this->argument1 = $argument1;
        $this->argument2 = $argument2;
        $this->argument3 = $argument3;
    }

with unexpected changes applied when running PHP CS Fixer:

    /**
     * constructor.
     */
    public function __construct(
        Type $argument1,
        Type $argument2,
        Type $argument3,
    ) {
        $this->argument1 = $argument1;
        $this->argument2 = $argument2;
        $this->argument3 = $argument3;
    }

with the changes you expected instead:

    /**
     * constructor.
     */
    public function __construct(
        Type $argument1,
        Type $argument2,
        Type $argument3,
    )
    {
        $this->argument1 = $argument1;
        $this->argument2 = $argument2;
        $this->argument3 = $argument3;
    }

Closing comment (2022-08-27T05:52:24Z): I think we can close this one, it is a duplicate of #3637 and I don't think we should support this CS.