Skip to content

Enable curly_braces_position #6505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

paulbalandan
Copy link
Member

Description

$ vendor/bin/php-cs-fixer describe curly_braces_position
Description of curly_braces_position rule.
Curly braces must be placed as configured.

Fixer is configurable using following options:
* control_structures_opening_brace ('next_line_unless_newline_at_signature_end', 'same_line'): the position of the opening brace of control structures body; defaults to 'same_line'
* functions_opening_brace ('next_line_unless_newline_at_signature_end', 'same_line'): the position of the opening brace of functions body; defaults to 'next_line_unless_newline_at_signature_end'
* anonymous_functions_opening_brace ('next_line_unless_newline_at_signature_end', 'same_line'): the position of the opening brace of anonymous functions body; defaults to 'same_line'
* classes_opening_brace ('next_line_unless_newline_at_signature_end', 'same_line'): the position of the opening brace of classes body; defaults to 'next_line_unless_newline_at_signature_end'
* anonymous_classes_opening_brace ('next_line_unless_newline_at_signature_end', 'same_line'): the position of the opening brace of anonymous classes body; defaults to 'same_line'
* allow_single_line_empty_anonymous_classes (bool): allow anonymous classes to have opening and closing braces on the same line; defaults to true
* allow_single_line_anonymous_functions (bool): allow anonymous functions to have opening and closing braces on the same line; defaults to true

Fixing examples:
 * Example #1. Fixing with the default configuration.
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,15 +1,15 @@
    <?php
   -class Foo {
   +class Foo
   +{
    }

   -function foo() {
   +function foo()
   +{
    }

   -$foo = function()
   -{
   +$foo = function() {
    };

   -if (foo())
   -{
   +if (foo()) {
        bar();
    }

   ----------- end diff -----------

 * Example #2. Fixing with the default configuration.
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,4 +1,3 @@
    <?php
   -$foo = new class
   -{
   +$foo = new class {
    };

   ----------- end diff -----------

 * Example #3. Fixing with configuration: ['control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end']. 
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,4 +1,5 @@
    <?php
   -if (foo()) {
   +if (foo())
   +{
        bar();
    }

   ----------- end diff -----------

 * Example #4. Fixing with configuration: ['functions_opening_brace' => 'same_line'].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,4 +1,3 @@
    <?php
   -function foo()
   -{
   +function foo() {
    }

   ----------- end diff -----------

 * Example #5. Fixing with configuration: ['anonymous_functions_opening_brace' => 'next_line_unless_newline_at_signature_end'].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,3 +1,4 @@
    <?php
   -$foo = function () {
   +$foo = function ()
   +{
    };

   ----------- end diff -----------

 * Example #6. Fixing with configuration: ['classes_opening_brace' => 'same_line'].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,4 +1,3 @@
    <?php
   -class Foo
   -{
   +class Foo {
    }

   ----------- end diff -----------

 * Example #7. Fixing with configuration: ['anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end'].  
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,3 +1,4 @@
    <?php
   -$foo = new class {
   +$foo = new class
   +{
    };

   ----------- end diff -----------

 * Example #8. Fixing with configuration: ['allow_single_line_empty_anonymous_classes' => true].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,3 +1,5 @@
    <?php
    $foo = new class { };
   -$bar = new class { private $baz; };
   +$bar = new class {
   +private $baz;
   +};

   ----------- end diff -----------

 * Example #9. Fixing with configuration: ['allow_single_line_anonymous_functions' => true].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,4 +1,6 @@
    <?php
    $foo = function () { return true; };
   -$bar = function () { $result = true;
   -    return $result; };
   +$bar = function () {
   +$result = true;
   +    return $result;
   +};

   ----------- end diff -----------

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@paulbalandan paulbalandan merged commit d5961a3 into codeigniter4:develop Sep 8, 2022
@paulbalandan paulbalandan deleted the curly-braces-position branch September 8, 2022 03:31
paulbalandan added a commit to CodeIgniter/coding-standard that referenced this pull request Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants