Skip to content
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

chore: DescribeCommand - better handling of deprecations #7778

Merged

Conversation

kubawerlos
Copy link
Contributor

@kubawerlos kubawerlos commented Jan 24, 2024

Resolves #7772

With the changes the command will display

$ PHP_CS_FIXER_FUTURE_MODE=0 php php-cs-fixer describe braces -vvv
PHP CS Fixer 3.48.1-DEV Small Changes by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.2
Description of the `braces` rule.

Fixer class: PhpCsFixer\Fixer\Basic\BracesFixer.

DEPRECATED: use `single_space_around_construct`, `control_structure_braces`, `control_structure_continuation_position`, `declare_parentheses`, `no_multiple_statements_per_line`, `curly_braces_position`, `statement_indentation` and `no_extra_blank_lines` instead.

The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.

Fixer is configurable using following options:
* allow_single_line_anonymous_class_with_empty_body (bool): whether single line anonymous class with empty body notation should be allowed; defaults to false
* allow_single_line_closure (bool): whether single line lambda notation should be allowed; defaults to false
* position_after_anonymous_constructs ('next' and 'same'): whether the opening brace should be placed on "next" or "same" line after anonymous constructs (anonymous classes and lambda functions); defaults to 'same'
* position_after_control_structures ('next' and 'same'): whether the opening brace should be placed on "next" or "same" line after control structures; defaults to 'same'
* position_after_functions_and_oop_constructs ('next' and 'same'): whether the opening brace should be placed on "next" or "same" line after classy constructs (non-anonymous classes, interfaces, traits, methods and non-lambda functions); defaults to 'next'

Fixing examples:
 * Example #1. Fixing with the default configuration.
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,25 +1,27 @@
    <?php

   -class Foo {
   -    public function bar($baz) {
   -        if ($baz = 900) echo "Hello!";
   +class Foo
   +{
   +    public function bar($baz)
   +    {
   +        if ($baz = 900) {
   +            echo "Hello!";
   +        }

   -        if ($baz = 9000)
   +        if ($baz = 9000) {
                echo "Wait!";
   +        }

   -        if ($baz == true)
   -        {
   +        if ($baz == true) {
                echo "Why?";
   -        }
   -        else
   -        {
   +        } else {
                echo "Ha?";
            }

   -        if (is_array($baz))
   -            foreach ($baz as $b)
   -            {
   +        if (is_array($baz)) {
   +            foreach ($baz as $b) {
                    echo $b;
                }
   +        }
        }
    }

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

 * Example #2. Fixing with configuration: ['allow_single_line_closure' => true].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,4 +1,5 @@
    <?php
    $positive = function ($item) { return $item >= 0; };
    $negative = function ($item) {
   -                return $item < 0; };
   +    return $item < 0;
   +};

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

 * Example #3. Fixing with configuration: ['position_after_functions_and_oop_constructs' => 'same'].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,27 +1,25 @@
    <?php

   -class Foo
   -{
   -    public function bar($baz)
   -    {
   -        if ($baz = 900) echo "Hello!";
   +class Foo {
   +    public function bar($baz) {
   +        if ($baz = 900) {
   +            echo "Hello!";
   +        }

   -        if ($baz = 9000)
   +        if ($baz = 9000) {
                echo "Wait!";
   +        }

   -        if ($baz == true)
   -        {
   +        if ($baz == true) {
                echo "Why?";
   -        }
   -        else
   -        {
   +        } else {
                echo "Ha?";
            }

   -        if (is_array($baz))
   -            foreach ($baz as $b)
   -            {
   +        if (is_array($baz)) {
   +            foreach ($baz as $b) {
                    echo $b;
                }
   +        }
        }
    }

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


Detected deprecations in use:
- Rule "braces" is deprecated. Use "single_space_around_construct", "control_structure_braces", "control_structure_continuation_position", "declare_parentheses", "no_multiple_statements_per_line", "curly_braces_position", "statement_indentation" and "no_extra_blank_lines" instead.
- Rule set "@PER" is deprecated. Use "@PER-CS" instead.
- Rule set "@PER:risky" is deprecated. Use "@PER-CS:risky" instead.

and

$ PHP_CS_FIXER_FUTURE_MODE=1 php php-cs-fixer describe braces
PHP CS Fixer 3.48.1-DEV Small Changes by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.2
Description of the `braces` rule.


In Utils.php line 174:

  Your are using something deprecated, see previous exception. Aborting execution because `PHP_CS_FIXER_FUTURE_MODE` environment variable is
  set.


In DescribeCommand.php line 171:

  Rule "braces" is deprecated. Use "single_space_around_construct", "control_structure_braces", "control_structure_continuation_position", "d
  eclare_parentheses", "no_multiple_statements_per_line", "curly_braces_position", "statement_indentation" and "no_extra_blank_lines" instead
  .


describe [--config CONFIG] [--] <name>

@coveralls
Copy link

coveralls commented Jan 24, 2024

Coverage Status

coverage: 94.756% (+0.001%) from 94.755%
when pulling 5f476c5 on 6b7562617765726c6f73:improve_describe_command
into 8a50ef3 on PHP-CS-Fixer:master.

@Wirone Wirone enabled auto-merge (squash) January 25, 2024 09:05
@Wirone Wirone merged commit dcaee18 into PHP-CS-Fixer:master Jan 25, 2024
25 checks passed
@kubawerlos kubawerlos deleted the improve_describe_command branch January 25, 2024 09:32
@Wirone
Copy link
Member

Wirone commented Jan 25, 2024

Thank you @kubawerlos 🍻!

danog pushed a commit to zoonru/PHP-CS-Fixer that referenced this pull request Feb 2, 2024
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.

Running php-cs-fixer describe {rule} causes unexpected deprecated notices
3 participants