Browse Source

feature: NoUselessConcatOperatorFixer - Introduction (#6447)

SpacePossum 2 years ago
parent
commit
aafad72ef3

+ 1 - 0
.php-cs-fixer.dist.php

@@ -46,6 +46,7 @@ $config
         'header_comment' => ['header' => $header],
         'heredoc_indentation' => false, // TODO switch on when # of PR's is lower
         'modernize_strpos' => true, // needs PHP 8+ or polyfill
+        'no_useless_concat_operator' => false, // TODO switch back on when the `src/Console/Application.php` no longer needs the concat
         'use_arrow_functions' => false, // TODO switch on when # of PR's is lower
     ])
     ->setFinder($finder)

+ 15 - 0
doc/list.rst

@@ -1749,6 +1749,21 @@ List of Available Rules
    Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_
 
    `Source PhpCsFixer\\Fixer\\Import\\NoUnusedImportsFixer <./../src/Fixer/Import/NoUnusedImportsFixer.php>`_
+-  `no_useless_concat_operator <./rules/operator/no_useless_concat_operator.rst>`_
+
+   There should not be useless concat operations.
+
+   Configuration options:
+
+   - | ``juggle_simple_strings``
+     | Allow for simple string quote juggling if it results in more concat-operations merges.
+     | Allowed types: ``bool``
+     | Default value: ``false``
+
+
+   Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_
+
+   `Source PhpCsFixer\\Fixer\\Operator\\NoUselessConcatOperatorFixer <./../src/Fixer/Operator/NoUselessConcatOperatorFixer.php>`_
 -  `no_useless_else <./rules/control_structure/no_useless_else.rst>`_
 
    There should not be useless ``else`` cases.

+ 1 - 0
doc/ruleSets/Symfony.rst

@@ -78,6 +78,7 @@ Rules
 - `no_unneeded_import_alias <./../rules/import/no_unneeded_import_alias.rst>`_
 - `no_unset_cast <./../rules/cast_notation/no_unset_cast.rst>`_
 - `no_unused_imports <./../rules/import/no_unused_imports.rst>`_
+- `no_useless_concat_operator <./../rules/operator/no_useless_concat_operator.rst>`_
 - `no_useless_nullsafe_operator <./../rules/operator/no_useless_nullsafe_operator.rst>`_
 - `no_whitespace_before_comma_in_array <./../rules/array_notation/no_whitespace_before_comma_in_array.rst>`_
 - `normalize_index_brace <./../rules/array_notation/normalize_index_brace.rst>`_

+ 3 - 0
doc/rules/index.rst

@@ -526,6 +526,9 @@ Operator
 - `no_space_around_double_colon <./operator/no_space_around_double_colon.rst>`_
 
   There must be no space around double colons (also called Scope Resolution Operator or Paamayim Nekudotayim).
+- `no_useless_concat_operator <./operator/no_useless_concat_operator.rst>`_
+
+  There should not be useless concat operations.
 - `no_useless_nullsafe_operator <./operator/no_useless_nullsafe_operator.rst>`_
 
   There should not be useless ``null-safe-operators`` ``?->`` used.

+ 58 - 0
doc/rules/operator/no_useless_concat_operator.rst

@@ -0,0 +1,58 @@
+===================================
+Rule ``no_useless_concat_operator``
+===================================
+
+There should not be useless concat operations.
+
+Configuration
+-------------
+
+``juggle_simple_strings``
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Allow for simple string quote juggling if it results in more concat-operations
+merges.
+
+Allowed types: ``bool``
+
+Default value: ``false``
+
+Examples
+--------
+
+Example #1
+~~~~~~~~~~
+
+*Default* configuration.
+
+.. code-block:: diff
+
+   --- Original
+   +++ New
+    <?php
+   -$a = 'a'.'b';
+   +$a = 'ab';
+
+Example #2
+~~~~~~~~~~
+
+With configuration: ``['juggle_simple_strings' => true]``.
+
+.. code-block:: diff
+
+   --- Original
+   +++ New
+    <?php
+   -$a = 'a'."b";
+   +$a = "ab";
+
+Rule sets
+---------
+
+The rule is part of the following rule sets:
+
+@PhpCsFixer
+  Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_useless_concat_operator`` rule with the default config.
+
+@Symfony
+  Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``no_useless_concat_operator`` rule with the default config.

+ 1 - 1
src/Fixer/Alias/BacktickToShellExecFixer.php

@@ -63,7 +63,7 @@ EOT
      */
     public function getPriority(): int
     {
-        return 2;
+        return 17;
     }
 
     /**

+ 10 - 0
src/Fixer/Alias/EregToPregFixer.php

@@ -60,6 +60,16 @@ final class EregToPregFixer extends AbstractFixer
         );
     }
 
+    /**
+     * {@inheritdoc}
+     *
+     * Must run after NoUselessConcatOperatorFixer.
+     */
+    public function getPriority(): int
+    {
+        return 0;
+    }
+
     /**
      * {@inheritdoc}
      */

+ 1 - 1
src/Fixer/Alias/SetTypeToCastFixer.php

@@ -48,7 +48,7 @@ settype($bar, "null");
     /**
      * {@inheritdoc}
      *
-     * Must run after NoBinaryStringFixer.
+     * Must run after NoBinaryStringFixer, NoUselessConcatOperatorFixer.
      */
     public function getPriority(): int
     {

+ 10 - 0
src/Fixer/FunctionNotation/DateTimeCreateFromFormatCallFixer.php

@@ -42,6 +42,16 @@ final class DateTimeCreateFromFormatCallFixer extends AbstractFixer
         );
     }
 
+    /**
+     * {@inheritdoc}
+     *
+     * Must run after NoUselessConcatOperatorFixer.
+     */
+    public function getPriority(): int
+    {
+        return 0;
+    }
+
     public function isCandidate(Tokens $tokens): bool
     {
         return $tokens->isTokenKindFound(T_DOUBLE_COLON);

+ 1 - 1
src/Fixer/FunctionNotation/RegularCallableCallFixer.php

@@ -62,7 +62,7 @@ call_user_func(static function ($a, $b) { var_dump($a, $b); }, 1, 2);
      * {@inheritdoc}
      *
      * Must run before NativeFunctionInvocationFixer.
-     * Must run after NoBinaryStringFixer.
+     * Must run after NoBinaryStringFixer, NoUselessConcatOperatorFixer.
      */
     public function getPriority(): int
     {

Some files were not shown because too many files changed in this diff