Browse Source

Merge branch '2.9'

Dariusz Ruminski 7 years ago
parent
commit
5d49b78e01

+ 5 - 5
README.rst

@@ -395,7 +395,7 @@ Choose from the list of available rules:
   Replaces ``dirname(__FILE__)`` expression with equivalent ``__DIR__``
   constant.
 
-  *Risky rule: risky when the function ``dirname()`` is overridden.*
+  *Risky rule: risky when the function ``dirname`` is overridden.*
 
 * **doctrine_annotation_array_assignment** [@DoctrineAnnotation]
 
@@ -670,9 +670,9 @@ Choose from the list of available rules:
 
 * **is_null** [@Symfony:risky]
 
-  Replaces is_null(parameter) expression with ``null === parameter``.
+  Replaces ``is_null($var)`` expression with ``null === $var``.
 
-  *Risky rule: risky when the function ``is_null()`` is overridden.*
+  *Risky rule: risky when the function ``is_null`` is overridden.*
 
   Configuration options:
 
@@ -1254,9 +1254,9 @@ Choose from the list of available rules:
 
 * **pow_to_exponentiation** [@PHP56Migration:risky, @PHP70Migration:risky, @PHP71Migration:risky]
 
-  Converts ``pow()`` to the ``**`` operator.
+  Converts ``pow`` to the ``**`` operator.
 
-  *Risky rule: risky when the function ``pow()`` is overridden.*
+  *Risky rule: risky when the function ``pow`` is overridden.*
 
 * **pre_increment**
 

+ 2 - 2
src/Fixer/Alias/PowToExponentiationFixer.php

@@ -40,14 +40,14 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
     public function getDefinition()
     {
         return new FixerDefinition(
-           'Converts `pow()` to the `**` operator.',
+            'Converts `pow` to the `**` operator.',
             [
                 new CodeSample(
                     "<?php\n pow(\$a, 1);\n"
                 ),
             ],
             null,
-            'Risky when the function `pow()` is overridden.'
+            'Risky when the function `pow` is overridden.'
         );
     }
 

+ 7 - 1
src/Fixer/Comment/SingleLineCommentStyleFixer.php

@@ -122,7 +122,13 @@ $c = 3;
 
                 continue;
             }
-            if (!$this->asteriskEnabled || '/*' !== substr($content, 0, 2) || 1 === preg_match('/[^\s\*].*\R.*[^\s\*]/s', $commentContent)) {
+
+            if (
+                !$this->asteriskEnabled
+                || false !== strpos($commentContent, '?>')
+                || '/*' !== substr($content, 0, 2)
+                || 1 === preg_match('/[^\s\*].*\R.*[^\s\*]/s', $commentContent)
+            ) {
                 continue;
             }
 

+ 1 - 1
src/Fixer/LanguageConstruct/DirConstantFixer.php

@@ -32,7 +32,7 @@ final class DirConstantFixer extends AbstractFunctionReferenceFixer
             'Replaces `dirname(__FILE__)` expression with equivalent `__DIR__` constant.',
             [new CodeSample("<?php\n\$a = dirname(__FILE__);\n")],
             null,
-            'Risky when the function `dirname()` is overridden.'
+            'Risky when the function `dirname` is overridden.'
         );
     }
 

+ 7 - 0
src/Fixer/LanguageConstruct/FunctionToConstantFixer.php

@@ -159,6 +159,13 @@ final class FunctionToConstantFixer extends AbstractFixer implements Configurati
         $tokens->clearTokenAndMergeSurroundingWhitespace($braceCloseIndex);
         $tokens->clearTokenAndMergeSurroundingWhitespace($braceOpenIndex);
 
+        if ($replacementConst->isMagicConstant()) {
+            $prevIndex = $tokens->getPrevMeaningfulToken($index);
+            $prevToken = $tokens[$prevIndex];
+            if ($prevToken->isGivenKind(T_NS_SEPARATOR)) {
+                $tokens->clearAt($prevIndex);
+            }
+        }
         $tokens->clearAt($index);
         $tokens->insertAt($index, $replacementConst);
     }

+ 11 - 2
src/Fixer/LanguageConstruct/IsNullFixer.php

@@ -33,16 +33,25 @@ final class IsNullFixer extends AbstractFixer implements ConfigurationDefinition
     public function getDefinition()
     {
         return new FixerDefinition(
-            'Replaces is_null(parameter) expression with `null === parameter`.',
+            'Replaces `is_null($var)` expression with `null === $var`.',
             [
                 new CodeSample("<?php\n\$a = is_null(\$b);\n"),
                 new CodeSample("<?php\n\$a = is_null(\$b);\n", ['use_yoda_style' => false]),
             ],
             null,
-            'Risky when the function `is_null()` is overridden.'
+            'Risky when the function `is_null` is overridden.'
         );
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getPriority()
+    {
+        // must be run before YodaStyleFixer
+        return 1;
+    }
+
     /**
      * {@inheritdoc}
      */

+ 1 - 1
src/Fixer/Phpdoc/PhpdocSummaryFixer.php

@@ -116,7 +116,7 @@ function foo () {}
      */
     private function isCorrectlyFormatted($content)
     {
-        if (false !== strpos(strtolower($content), '{@inheritdoc}')) {
+        if (false !== stripos($content, '{@inheritdoc}')) {
             return true;
         }
 

+ 1 - 0
tests/AutoReview/FixerFactoryTest.php

@@ -83,6 +83,7 @@ final class FixerFactoryTest extends TestCase
             [$fixers['function_to_constant'], $fixers['no_trailing_whitespace']], // tested also in: function_to_constant,no_trailing_whitespace.test
             [$fixers['function_to_constant'], $fixers['no_whitespace_in_blank_line']], // tested also in: function_to_constant,no_whitespace_in_blank_line.test
             [$fixers['indentation_type'], $fixers['phpdoc_indent']],
+            [$fixers['is_null'], $fixers['yoda_style']], // tested also in: is_null,yoda_style.test
             [$fixers['line_ending'], $fixers['single_blank_line_at_eof']],
             [$fixers['list_syntax'], $fixers['binary_operator_spaces']], // tested also in: list_syntax,binary_operator_spaces.test
             [$fixers['list_syntax'], $fixers['ternary_operator_spaces']], // tested also in: list_syntax,ternary_operator_spaces.test

+ 1 - 1
tests/Console/Output/ErrorOutputTest.php

@@ -40,7 +40,7 @@ final class ErrorOutputTest extends TestCase
     {
         $source = $error->getSource();
 
-        $output = new StreamOutput(fopen('php://memory', 'bw', false));
+        $output = new StreamOutput(fopen('php://memory', 'wb', false));
         $output->setDecorated(false);
         $output->setVerbosity($verbosityLevel);
 

+ 7 - 0
tests/Fixer/Comment/SingleLineCommentStyleFixerTest.php

@@ -317,6 +317,13 @@ second line*/',
     # 5
 ',
             ],
+            [
+                '<?php
+                function foo() {
+                    /* ?> */
+                    return "bar";
+                }',
+            ],
         ];
     }
 }

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