Browse Source

Merge branch '1.12'

Conflicts:
	README.rst
	Symfony/CS/Fixer/Contrib/AlignEqualsFixer.php
	Symfony/CS/Fixer/Symfony/UnneededControlParenthesesFixer.php
	Symfony/CS/Tests/Fixer/Contrib/PhpUnitConstructFixerTest.php
	Symfony/CS/Tests/Fixer/PSR2/EofEndingFixerTest.php
	Symfony/CS/Tests/Fixer/PSR2/MultipleUseFixerTest.php
	Symfony/CS/Tests/Fixer/Symfony/UnneededControlParenthesesFixerTest.php
	Symfony/CS/Tests/FixerTest.php
	Symfony/CS/Tests/Tokenizer/TokensTest.php
Dariusz Ruminski 9 years ago
parent
commit
a86be6ac1a

+ 3 - 3
.travis.yml

@@ -8,10 +8,10 @@ matrix:
         - php: 5.4
         - php: 5.5
         - php: 5.6
-          env: SYMFONY_VERSION="~2.7"
-        - php: 5.6
-          env: SYMFONY_VERSION="~3.0@dev" COMPOSER_FLAGS="--prefer-stable"
         - php: 7.0
+          env: SYMFONY_VERSION="~2.8"
+        - php: 7.0
+          env: SYMFONY_VERSION="~3.0"
         - php: hhvm
 
 sudo: false

+ 4 - 0
README.rst

@@ -598,6 +598,10 @@ Choose from the list of available fixers:
                         single quotes for simple
                         strings.
 
+* **spaces_after_semicolon** [@Symfony]
+                        Fix whitespace after a
+                        semicolon.
+
 * **spaces_before_semicolon** [@Symfony]
                         Single-line whitespace before
                         closing semicolon are

+ 1 - 1
Symfony/CS/DocBlock/Annotation.php

@@ -88,7 +88,7 @@ class Annotation
     /**
      * Get all the annotation tag names with types.
      *
-     * @var string[]
+     * @return string[]
      */
     public static function getTagsWithTypes()
     {

+ 1 - 1
Symfony/CS/Fixer/Contrib/PhpUnitConstructFixer.php

@@ -44,7 +44,7 @@ final class PhpUnitConstructFixer extends AbstractFixer
 
         foreach ($usingMethods as $method => $fix) {
             if (!isset($this->configuration[$method])) {
-                throw new \InvalidArgumentException();
+                throw new \InvalidArgumentException(sprintf('Configured method "%s" cannot be fixed by this fixer.', $method));
             }
 
             $this->configuration[$method] = $fix;

+ 0 - 4
Symfony/CS/Fixer/PSR2/LowercaseConstantsFixer.php

@@ -87,10 +87,6 @@ final class LowercaseConstantsFixer extends AbstractFixer
             }
         }
 
-        if (null === $index) {
-            return true;
-        }
-
         $token = $tokens[$index];
 
         if ($token->equalsAny(array('{', '}'))) {

+ 2 - 2
Symfony/CS/Fixer/Symfony/MethodArgumentDefaultValueFixer.php

@@ -121,7 +121,7 @@ final class MethodArgumentDefaultValueFixer extends AbstractFixer
      */
     private function isEllipsis(Tokens $tokens, $variableIndex)
     {
-        if (PHP_VERSION_ID < 50600) {
+        if (!defined('T_ELLIPSIS')) {
             return $tokens[$tokens->getPrevMeaningfulToken($variableIndex)]->equals('.');
         }
 
@@ -187,7 +187,7 @@ final class MethodArgumentDefaultValueFixer extends AbstractFixer
         $typehintedTokens = array(array(T_STRING), array(CT_ARRAY_TYPEHINT), ',', '(');
         $typehintedKinds = array(T_STRING, CT_ARRAY_TYPEHINT);
 
-        if (PHP_VERSION_ID >= 50400) {
+        if (defined('T_CALLABLE')) {
             $typehintedTokens[] = array(T_CALLABLE);
             $typehintedKinds[] = T_CALLABLE;
         }

+ 1 - 1
Symfony/CS/Fixer/Symfony/MethodSeparationFixer.php

@@ -58,7 +58,7 @@ final class MethodSeparationFixer extends AbstractFixer
     {
         $tokensAnalyzer = new TokensAnalyzer($tokens);
 
-        for ($index = $tokens->getSize() - 1; $index > 0;--$index) {
+        for ($index = $tokens->getSize() - 1; $index > 0; --$index) {
             if (!$tokens[$index]->isClassy()) {
                 continue;
             }

+ 56 - 0
Symfony/CS/Fixer/Symfony/SpacesAfterSemicolonFixer.php

@@ -0,0 +1,56 @@
+<?php
+
+/*
+ * This file is part of the PHP CS utility.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\CS\Fixer\Symfony;
+
+use Symfony\CS\AbstractFixer;
+use Symfony\CS\Tokenizer\Token;
+use Symfony\CS\Tokenizer\Tokens;
+
+/**
+ * @author SpacePossum
+ */
+final class SpacesAfterSemicolonFixer extends AbstractFixer
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function isCandidate(Tokens $tokens)
+    {
+        return $tokens->isTokenKindFound(';');
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function fix(\SplFileInfo $file, Tokens $tokens)
+    {
+        for ($index = count($tokens) - 3; $index > 0; --$index) {
+            if (!$tokens[$index]->equals(';') || $tokens[$index + 2]->isComment()) {
+                continue;
+            }
+
+            if (!$tokens[$index + 1]->isWhitespace()) {
+                $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
+            } elseif (!$tokens[$index + 1]->equals(array(T_WHITESPACE, ' ')) && $tokens[$index + 1]->isWhitespace(" \t")) {
+                $tokens[$index + 1]->setContent(' ');
+            }
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getDescription()
+    {
+        return 'Fix whitespace after a semicolon.';
+    }
+}

+ 5 - 5
Symfony/CS/Fixer/Symfony/TernarySpacesFixer.php

@@ -53,24 +53,24 @@ final class TernarySpacesFixer extends AbstractFixer
                     }
                 } else {
                     // for `$a ? $b : $c` ensure space after `?`
-                    $this->ensureWhitespaceExistance($tokens, $index + 1, true);
+                    $this->ensureWhitespaceExistence($tokens, $index + 1, true);
                 }
 
                 // for `$a ? $b : $c` ensure space before `?`
-                $this->ensureWhitespaceExistance($tokens, $index - 1, false);
+                $this->ensureWhitespaceExistence($tokens, $index - 1, false);
 
                 continue;
             }
 
             if ($ternaryLevel && $token->equals(':')) {
                 // for `$a ? $b : $c` ensure space after `:`
-                $this->ensureWhitespaceExistance($tokens, $index + 1, true);
+                $this->ensureWhitespaceExistence($tokens, $index + 1, true);
 
                 $prevNonWhitespaceToken = $tokens[$tokens->getPrevNonWhitespace($index)];
 
                 if (!$prevNonWhitespaceToken->equals('?')) {
                     // for `$a ? $b : $c` ensure space before `:`
-                    $this->ensureWhitespaceExistance($tokens, $index - 1, false);
+                    $this->ensureWhitespaceExistence($tokens, $index - 1, false);
                 }
 
                 --$ternaryLevel;
@@ -86,7 +86,7 @@ final class TernarySpacesFixer extends AbstractFixer
         return 'Standardize spaces around ternary operator.';
     }
 
-    private function ensureWhitespaceExistance(Tokens $tokens, $index, $after)
+    private function ensureWhitespaceExistence(Tokens $tokens, $index, $after)
     {
         $indexChange = $after ? 0 : 1;
         $token = $tokens[$index];

+ 10 - 6
Symfony/CS/Fixer/Symfony/UnneededControlParenthesesFixer.php

@@ -17,6 +17,7 @@ use Symfony\CS\Tokenizer\Tokens;
 /**
  * @author Sullivan Senechal <soullivaneuh@gmail.com>
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ * @author Gregor Harlan <gharlan@web.de>
  */
 final class UnneededControlParenthesesFixer extends AbstractFixer
 {
@@ -26,18 +27,22 @@ final class UnneededControlParenthesesFixer extends AbstractFixer
      * @var string[] List of statements to fix.
      */
     private $controlStatements = array(
-        'switch_case',
+        'break',
+        'clone',
+        'continue',
         'echo_print',
         'return',
-        'clone',
+        'switch_case',
         'yield',
     );
 
     private static $loops = array(
-        'switch_case' => array('lookupTokens' => T_CASE, 'neededSuccessors' => array(';', ':')),
+        'break' => array('lookupTokens' => T_BREAK, 'neededSuccessors' => array(';')),
+        'clone' => array('lookupTokens' => T_CLONE, 'neededSuccessors' => array(';', ':', ',', ')')),
+        'continue' => array('lookupTokens' => T_CONTINUE, 'neededSuccessors' => array(';')),
         'echo_print' => array('lookupTokens' => array(T_ECHO, T_PRINT), 'neededSuccessors' => array(';', array(T_CLOSE_TAG))),
         'return' => array('lookupTokens' => T_RETURN, 'neededSuccessors' => array(';')),
-        'clone' => array('lookupTokens' => T_CLONE, 'neededSuccessors' => array(';', ':', ',', ')')),
+        'switch_case' => array('lookupTokens' => T_CASE, 'neededSuccessors' => array(';', ':')),
     );
 
     /**
@@ -145,8 +150,7 @@ final class UnneededControlParenthesesFixer extends AbstractFixer
         $tokens[$index]->clear();
 
         if (
-            isset($tokens[$index - 1]) &&
-            isset($tokens[$index + 1]) &&
+            isset($tokens[$index - 1], $tokens[$index + 1]) &&
             $tokens[$index - 1]->isWhitespace() &&
             $tokens[$index + 1]->isWhitespace()
         ) {

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