Browse Source

Merge branch '2.15' into 2.16

Dariusz Ruminski 4 years ago
parent
commit
bde8ed8d00

+ 2 - 0
doc/ruleSets/PHP80MigrationRisky.rst

@@ -12,4 +12,6 @@ Rules
 - `no_alias_functions <./../rules/alias/no_alias_functions.rst>`_
   config:
   ``['sets' => ['@all']]``
+- `no_php4_constructor <./../rules/class_notation/no_php4_constructor.rst>`_
 - `no_unneeded_final_method <./../rules/class_notation/no_unneeded_final_method.rst>`_
+- `no_unreachable_default_argument_value <./../rules/function_notation/no_unreachable_default_argument_value.rst>`_

+ 1 - 0
doc/ruleSets/SymfonyRisky.rst

@@ -28,6 +28,7 @@ Rules
   ``['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true]``
 - `no_alias_functions <./../rules/alias/no_alias_functions.rst>`_
 - `no_homoglyph_names <./../rules/naming/no_homoglyph_names.rst>`_
+- `no_php4_constructor <./../rules/class_notation/no_php4_constructor.rst>`_
 - `no_unneeded_final_method <./../rules/class_notation/no_unneeded_final_method.rst>`_
 - `non_printable_character <./../rules/basic/non_printable_character.rst>`_
 - `php_unit_construct <./../rules/php_unit/php_unit_construct.rst>`_

+ 14 - 0
doc/rules/class_notation/no_php4_constructor.rst

@@ -28,3 +28,17 @@ Example #1
         {
         }
     }
+
+Rule sets
+---------
+
+The rule is part of the following rule sets:
+
+@PHP80Migration:risky
+  Using the `@PHP80Migration:risky <./../../ruleSets/PHP80MigrationRisky.rst>`_ rule set will enable the ``no_php4_constructor`` rule.
+
+@PhpCsFixer:risky
+  Using the `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_ rule set will enable the ``no_php4_constructor`` rule.
+
+@Symfony:risky
+  Using the `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_ rule set will enable the ``no_php4_constructor`` rule.

+ 4 - 1
doc/rules/function_notation/no_unreachable_default_argument_value.rst

@@ -29,7 +29,10 @@ Example #1
 Rule sets
 ---------
 
-The rule is part of the following rule set:
+The rule is part of the following rule sets:
+
+@PHP80Migration:risky
+  Using the `@PHP80Migration:risky <./../../ruleSets/PHP80MigrationRisky.rst>`_ rule set will enable the ``no_unreachable_default_argument_value`` rule.
 
 @PhpCsFixer:risky
   Using the `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_ rule set will enable the ``no_unreachable_default_argument_value`` rule.

+ 4 - 0
phpstan.neon

@@ -46,4 +46,8 @@ parameters:
         -
             message: '/^Parameter #1 \$finder of method PhpCsFixer\\Config::setFinder\(\) expects iterable<string>, int given\.$/'
             path: tests/ConfigTest.php
+
+        -
+            message: '/^Property .*::\$indicator .* does not accept null\.$/'
+            path: tests/Indicator/PhpUnitTestCaseIndicatorTest.php
     tipsOfTheDay: false

+ 17 - 6
src/Fixer/Alias/PowToExponentiationFixer.php

@@ -30,7 +30,7 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
      */
     public function isCandidate(Tokens $tokens)
     {
-        // minimal candidate to fix is seven tokens: pow(x,x);
+        // minimal candidate to fix is seven tokens: pow(x,y);
         return $tokens->count() > 7 && $tokens->isTokenKindFound(T_STRING);
     }
 
@@ -68,9 +68,9 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
     {
         $candidates = $this->findPowCalls($tokens);
         $argumentsAnalyzer = new ArgumentsAnalyzer();
-
         $numberOfTokensAdded = 0;
         $previousCloseParenthesisIndex = \count($tokens);
+
         foreach (array_reverse($candidates) as $candidate) {
             // if in the previous iteration(s) tokens were added to the collection and this is done within the tokens
             // indexes of the current candidate than the index of the close ')' of the candidate has moved and so
@@ -84,10 +84,17 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
             }
 
             $arguments = $argumentsAnalyzer->getArguments($tokens, $candidate[1], $candidate[2]);
+
             if (2 !== \count($arguments)) {
                 continue;
             }
 
+            for ($i = $candidate[1]; $i < $candidate[2]; ++$i) {
+                if ($tokens[$i]->isGivenKind(T_ELLIPSIS)) {
+                    continue 2;
+                }
+            }
+
             $numberOfTokensAdded += $this->fixPowToExponentiation(
                 $tokens,
                 $candidate[0], // functionNameIndex,
@@ -105,12 +112,13 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
     {
         $candidates = [];
 
-        // Minimal candidate to fix is seven tokens: pow(x,x);
+        // Minimal candidate to fix is seven tokens: pow(x,y);
         $end = \count($tokens) - 6;
 
         // First possible location is after the open token: 1
         for ($i = 1; $i < $end; ++$i) {
             $candidate = $this->find('pow', $tokens, $i, $end);
+
             if (null === $candidate) {
                 break;
             }
@@ -139,11 +147,13 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
         // clean up the function call tokens prt. I
         $tokens->clearAt($closeParenthesisIndex);
         $previousIndex = $tokens->getPrevMeaningfulToken($closeParenthesisIndex);
+
         if ($tokens[$previousIndex]->equals(',')) {
             $tokens->clearAt($previousIndex); // trailing ',' in function call (PHP 7.3)
         }
 
         $added = 0;
+
         // check if the arguments need to be wrapped in parenthesis
         foreach (array_reverse($arguments, true) as $argumentStartIndex => $argumentEndIndex) {
             if ($this->isParenthesisNeeded($tokens, $argumentStartIndex, $argumentEndIndex)) {
@@ -157,9 +167,10 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
         $tokens->clearAt($openParenthesisIndex);
         $tokens->clearAt($functionNameIndex);
 
-        $prev = $tokens->getPrevMeaningfulToken($functionNameIndex);
-        if ($tokens[$prev]->isGivenKind(T_NS_SEPARATOR)) {
-            $tokens->clearAt($prev);
+        $prevMeaningfulTokenIndex = $tokens->getPrevMeaningfulToken($functionNameIndex);
+
+        if ($tokens[$prevMeaningfulTokenIndex]->isGivenKind(T_NS_SEPARATOR)) {
+            $tokens->clearAt($prevMeaningfulTokenIndex);
         }
 
         return $added;

+ 1 - 0
src/Fixer/Operator/TernaryToNullCoalescingFixer.php

@@ -182,6 +182,7 @@ final class TernaryToNullCoalescingFixer extends AbstractFixer
             '^',
             '|',
             '~',
+            '.',
         ];
 
         return isset($operatorsPerId[$token->getId()]) || $token->equalsAny($operatorsPerContent);

+ 2 - 0
src/RuleSet/Sets/PHP80MigrationRiskySet.php

@@ -29,7 +29,9 @@ final class PHP80MigrationRiskySet extends AbstractRuleSetDescription
                     '@all',
                 ],
             ],
+            'no_php4_constructor' => true,
             'no_unneeded_final_method' => true,
+            'no_unreachable_default_argument_value' => true,
         ];
     }
 

+ 1 - 0
src/RuleSet/Sets/SymfonyRiskySet.php

@@ -60,6 +60,7 @@ final class SymfonyRiskySet extends AbstractRuleSetDescription
             ],
             'no_alias_functions' => true,
             'no_homoglyph_names' => true,
+            'no_php4_constructor' => true,
             'no_unneeded_final_method' => true,
             'non_printable_character' => true,
             'php_unit_construct' => true,

+ 3 - 0
tests/Fixer/Alias/PowToExponentiationFixerTest.php

@@ -222,6 +222,9 @@ final class PowToExponentiationFixerTest extends AbstractFixerTestCase
                 '<?php echo $a[1]** $b[2+5];',
                 '<?php echo pow($a[1], $b[2+5]);',
             ],
+            [
+                '<?php pow($b, ...$a);',
+            ],
         ];
 
         foreach ($tests as $index => $test) {

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