SpacePossum 8 лет назад
Родитель
Сommit
e74080b4fc

+ 3 - 0
src/Console/Command/FixCommand.php

@@ -30,6 +30,7 @@ use PhpCsFixer\Report\ReporterFactory;
 use PhpCsFixer\Report\ReportSummary;
 use PhpCsFixer\RuleSet;
 use PhpCsFixer\Runner\Runner;
+use PhpCsFixer\Tokenizer\Transformers;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
@@ -286,6 +287,8 @@ EOF
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
+        Transformers::create(); // make sure all transformers have defined custom tokens since configuration might depend on it
+
         $verbosity = $output->getVerbosity();
         $resolver = new ConfigurationResolver();
         $resolver

+ 0 - 3
src/Console/ConfigurationResolver.php

@@ -431,8 +431,6 @@ final class ConfigurationResolver
         );
 
         foreach ($paths as $path) {
-            $isFile = is_file($path);
-
             if (is_file($path)) {
                 $pathsByType['file'][] = $path;
             } else {
@@ -577,7 +575,6 @@ final class ConfigurationResolver
     private function resolvePath()
     {
         $filesystem = new Filesystem();
-        $path = $this->options['path'];
         $cwd = $this->cwd;
 
         $this->path = array_map(

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

@@ -44,7 +44,7 @@ final class EchoToPrintFixer extends AbstractFixer
 
             for ($i = $nextTokenIndex; $i < $endTokenIndex; ++$i) {
                 if ($tokens[$i]->equalsAny(array('(', array(CT_ARRAY_SQUARE_BRACE_OPEN)))) {
-                    $blockType = $tokens->detectBlockType($tokens[$i]);
+                    $blockType = Tokens::detectBlockType($tokens[$i]);
                     $i = $tokens->findBlockEnd($blockType['type'], $i);
                 }
 

+ 1 - 1
src/Fixer/ClassNotation/VisibilityRequiredFixer.php

@@ -52,7 +52,7 @@ final class VisibilityRequiredFixer extends AbstractFixer
             } elseif ('property' === $element['type']) {
                 $prevIndex = $tokens->getPrevTokenOfKind($index, array(';', ',', '{'));
 
-                if (!$prevIndex || !$tokens[$prevIndex]->equals(',')) {
+                if (null === $prevIndex || !$tokens[$prevIndex]->equals(',')) {
                     $this->overrideAttribs($tokens, $index, $this->grabAttribsBeforePropertyToken($tokens, $index));
                 }
             }

+ 1 - 4
src/Fixer/Operator/NotOperatorWithSpaceFixer.php

@@ -15,7 +15,6 @@ namespace PhpCsFixer\Fixer\Operator;
 use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
-use PhpCsFixer\Tokenizer\TokensAnalyzer;
 
 /**
  * @author Javier Spagnoletti <phansys@gmail.com>
@@ -35,12 +34,10 @@ final class NotOperatorWithSpaceFixer extends AbstractFixer
      */
     public function fix(\SplFileInfo $file, Tokens $tokens)
     {
-        $tokensAnalyzer = new TokensAnalyzer($tokens);
-
         for ($index = $tokens->count() - 1; $index >= 0; --$index) {
             $token = $tokens[$index];
 
-            if ($tokensAnalyzer->isUnaryPredecessorOperator($index) && $token->equals('!')) {
+            if ($token->equals('!')) {
                 if (!$tokens[$index + 1]->isWhitespace()) {
                     $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
                 }

+ 1 - 4
src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php

@@ -15,7 +15,6 @@ namespace PhpCsFixer\Fixer\Operator;
 use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
-use PhpCsFixer\Tokenizer\TokensAnalyzer;
 
 /**
  * @author Javier Spagnoletti <phansys@gmail.com>
@@ -35,12 +34,10 @@ final class NotOperatorWithSuccessorSpaceFixer extends AbstractFixer
      */
     public function fix(\SplFileInfo $file, Tokens $tokens)
     {
-        $tokensAnalyzer = new TokensAnalyzer($tokens);
-
         for ($index = $tokens->count() - 1; $index >= 0; --$index) {
             $token = $tokens[$index];
 
-            if ($tokensAnalyzer->isUnaryPredecessorOperator($index) && $token->equals('!')) {
+            if ($token->equals('!')) {
                 if (!$tokens[$index + 1]->isWhitespace()) {
                     $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
                 } else {

+ 1 - 1
src/Fixer/Operator/PreIncrementFixer.php

@@ -78,7 +78,7 @@ final class PreIncrementFixer extends AbstractFixer
             $index = $tokens->getPrevMeaningfulToken($index);
             $token = $tokens[$index];
 
-            $blockType = $tokens->detectBlockType($token);
+            $blockType = Tokens::detectBlockType($token);
             if (null !== $blockType && !$blockType['isStart']) {
                 $index = $tokens->findBlockEnd($blockType['type'], $index, false);
                 $token = $tokens[$index];

+ 0 - 5
src/Fixer/Whitespace/NoExtraConsecutiveBlankLinesFixer.php

@@ -17,7 +17,6 @@ use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
-use PhpCsFixer\Tokenizer\Transformers;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -66,10 +65,6 @@ final class NoExtraConsecutiveBlankLinesFixer extends AbstractFixer
             return;
         }
 
-        if (!defined('CT_USE_TRAIT')) {
-            Transformers::create(); // TODO could use a better fix
-        }
-
         $this->tokenKindCallbackMap = array();
         $this->tokenEqualsMap = array();
         foreach ($configuration as $item) {

+ 2 - 0
src/FixerInterface.php

@@ -95,6 +95,8 @@ interface FixerInterface
     /**
      * Returns true if the file is supported by this fixer.
      *
+     * @param \SplFileInfo $file
+     *
      * @return bool true if the file is supported by this fixer, false otherwise
      */
     public function supports(\SplFileInfo $file);

+ 1 - 3
src/Linter/Linter.php

@@ -118,9 +118,7 @@ final class Linter implements LinterInterface
             throw new IOException(sprintf('Failed to write file "%s".', $this->temporaryFile), 0, null, $this->temporaryFile);
         }
 
-        $process = $this->createProcessForFile($this->temporaryFile);
-
-        return $process;
+        return $this->createProcessForFile($this->temporaryFile);
     }
 
     /**

Некоторые файлы не были показаны из-за большого количества измененных файлов