Browse Source

Merge branch 'master' into 3.0

# Conflicts:
#	.composer-require-checker.json
#	.github/workflows/sca.yml
#	composer.json
#	src/Tokenizer/Tokens.php
Dariusz Ruminski 4 years ago
parent
commit
def9c7d0b8

+ 70 - 0
doc/rules/operator/binary_operator_spaces.rst

@@ -115,6 +115,76 @@ With configuration: ``['operators' => ['|' => 'no_space']]``.
    -$foo = \json_encode($bar, JSON_PRESERVE_ZERO_FRACTION | JSON_PRETTY_PRINT);
    +$foo = \json_encode($bar, JSON_PRESERVE_ZERO_FRACTION|JSON_PRETTY_PRINT);
 
+Example #6
+~~~~~~~~~~
+
+With configuration: ``['operators' => ['=>' => 'single_space']]``.
+
+.. code-block:: diff
+
+   --- Original
+   +++ New
+   @@ -1,5 +1,5 @@
+    <?php
+    $array = [
+   -    "foo"            =>   1,
+   -    "baaaaaaaaaaar"  =>  11,
+   +    "foo" => 1,
+   +    "baaaaaaaaaaar" => 11,
+    ];
+
+Example #7
+~~~~~~~~~~
+
+With configuration: ``['operators' => ['=>' => 'align']]``.
+
+.. code-block:: diff
+
+   --- Original
+   +++ New
+   @@ -1,5 +1,5 @@
+    <?php
+    $array = [
+   -    "foo" => 12,
+   +    "foo"            => 12,
+        "baaaaaaaaaaar"  => 13,
+    ];
+
+Example #8
+~~~~~~~~~~
+
+With configuration: ``['operators' => ['=>' => 'align_single_space']]``.
+
+.. code-block:: diff
+
+   --- Original
+   +++ New
+   @@ -1,5 +1,5 @@
+    <?php
+    $array = [
+   -    "foo" => 12,
+   +    "foo"            => 12,
+        "baaaaaaaaaaar"  => 13,
+    ];
+
+Example #9
+~~~~~~~~~~
+
+With configuration: ``['operators' => ['=>' => 'align_single_space_minimal']]``.
+
+.. code-block:: diff
+
+   --- Original
+   +++ New
+   @@ -1,5 +1,5 @@
+    <?php
+    $array = [
+   -    "foo" => 12,
+   -    "baaaaaaaaaaar"  => 13,
+   +    "foo"           => 12,
+   +    "baaaaaaaaaaar" => 13,
+    ];
+
 Rule sets
 ---------
 

+ 1 - 1
src/Console/ConfigurationResolver.php

@@ -323,7 +323,7 @@ final class ConfigurationResolver
                 );
 
                 if (\count($riskyFixers)) {
-                    throw new InvalidConfigurationException(sprintf('The rules contain risky fixers (%s), but they are not allowed to run. Perhaps you forget to use --allow-risky=yes option?', implode('", "', $riskyFixers)));
+                    throw new InvalidConfigurationException(sprintf('The rules contain risky fixers ("%s"), but they are not allowed to run. Perhaps you forget to use --allow-risky=yes option?', implode('", "', $riskyFixers)));
                 }
             }
         }

+ 36 - 0
src/Fixer/Operator/BinaryOperatorSpacesFixer.php

@@ -207,6 +207,42 @@ $foo = \json_encode($bar, JSON_PRESERVE_ZERO_FRACTION | JSON_PRETTY_PRINT);
 ',
                     ['operators' => ['|' => 'no_space']]
                 ),
+                new CodeSample(
+                    '<?php
+$array = [
+    "foo"            =>   1,
+    "baaaaaaaaaaar"  =>  11,
+];
+',
+                    ['operators' => ['=>' => 'single_space']]
+                ),
+                new CodeSample(
+                    '<?php
+$array = [
+    "foo" => 12,
+    "baaaaaaaaaaar"  => 13,
+];
+',
+                    ['operators' => ['=>' => 'align']]
+                ),
+                new CodeSample(
+                    '<?php
+$array = [
+    "foo" => 12,
+    "baaaaaaaaaaar"  => 13,
+];
+',
+                    ['operators' => ['=>' => 'align_single_space']]
+                ),
+                new CodeSample(
+                    '<?php
+$array = [
+    "foo" => 12,
+    "baaaaaaaaaaar"  => 13,
+];
+',
+                    ['operators' => ['=>' => 'align_single_space_minimal']]
+                ),
             ]
         );
     }

+ 1 - 11
src/Tokenizer/AbstractTransformer.php

@@ -43,15 +43,5 @@ abstract class AbstractTransformer implements TransformerInterface
     /**
      * {@inheritdoc}
      */
-    public function getCustomTokens()
-    {
-        @trigger_error(sprintf('%s is deprecated and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED);
-
-        return $this->getDeprecatedCustomTokens();
-    }
-
-    /**
-     * @return int[]
-     */
-    abstract protected function getDeprecatedCustomTokens();
+    abstract public function getCustomTokens();
 }

+ 13 - 3
src/Tokenizer/Tokens.php

@@ -25,8 +25,10 @@ use PhpCsFixer\Utils;
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  *
  * @extends \SplFixedArray<Token>
+ *
+ * @final
  */
-final class Tokens extends \SplFixedArray
+class Tokens extends \SplFixedArray
 {
     const BLOCK_TYPE_PARENTHESIS_BRACE = 1;
     const BLOCK_TYPE_CURLY_BRACE = 2;
@@ -1022,8 +1024,7 @@ final class Tokens extends \SplFixedArray
             $this[$index] = new Token($token);
         }
 
-        $transformers = Transformers::create();
-        $transformers->transform($this);
+        $this->applyTransformers();
 
         $this->foundTokenKinds = [];
 
@@ -1211,6 +1212,15 @@ final class Tokens extends \SplFixedArray
         $this->clearAt($nextIndex);
     }
 
+    /**
+     * @internal
+     */
+    protected function applyTransformers()
+    {
+        $transformers = Transformers::create();
+        $transformers->transform($this);
+    }
+
     private function warnPhp8SplFixerArrayChange($method)
     {
         if (80000 <= \PHP_VERSION_ID) {

+ 1 - 1
src/Tokenizer/Transformer/ArrayTypehintTransformer.php

@@ -54,7 +54,7 @@ final class ArrayTypehintTransformer extends AbstractTransformer
     /**
      * {@inheritdoc}
      */
-    protected function getDeprecatedCustomTokens()
+    public function getCustomTokens()
     {
         return [CT::T_ARRAY_TYPEHINT];
     }

+ 1 - 1
src/Tokenizer/Transformer/AttributeTransformer.php

@@ -68,7 +68,7 @@ final class AttributeTransformer extends AbstractTransformer
     /**
      * {@inheritdoc}
      */
-    protected function getDeprecatedCustomTokens()
+    public function getCustomTokens()
     {
         return [
             CT::T_ATTRIBUTE_CLOSE,

+ 1 - 1
src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php

@@ -81,7 +81,7 @@ final class BraceClassInstantiationTransformer extends AbstractTransformer
     /**
      * {@inheritdoc}
      */
-    protected function getDeprecatedCustomTokens()
+    public function getCustomTokens()
     {
         return [CT::T_BRACE_CLASS_INSTANTIATION_OPEN, CT::T_BRACE_CLASS_INSTANTIATION_CLOSE];
     }

+ 1 - 1
src/Tokenizer/Transformer/ClassConstantTransformer.php

@@ -57,7 +57,7 @@ final class ClassConstantTransformer extends AbstractTransformer
     /**
      * {@inheritdoc}
      */
-    protected function getDeprecatedCustomTokens()
+    public function getCustomTokens()
     {
         return [CT::T_CLASS_CONSTANT];
     }

+ 1 - 1
src/Tokenizer/Transformer/ConstructorPromotionTransformer.php

@@ -67,7 +67,7 @@ final class ConstructorPromotionTransformer extends AbstractTransformer
     /**
      * {@inheritdoc}
      */
-    protected function getDeprecatedCustomTokens()
+    public function getCustomTokens()
     {
         return [
             CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC,

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