Browse Source

Stop polluting global namespace with CT

Dariusz Ruminski 8 years ago
parent
commit
d76397efde

+ 2 - 1
src/AbstractFunctionReferenceFixer.php

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer;
 
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
@@ -84,7 +85,7 @@ abstract class AbstractFunctionReferenceFixer extends AbstractFixer
         if ($functionNamePrecedingToken->isGivenKind(T_NS_SEPARATOR)) {
             $namespaceCandidate = $tokens->getPrevMeaningfulToken($functionNamePrefix);
             $namespaceCandidateToken = $tokens[$namespaceCandidate];
-            if ($namespaceCandidateToken->isGivenKind(array(T_NEW, T_STRING, CT_NAMESPACE_OPERATOR))) {
+            if ($namespaceCandidateToken->isGivenKind(array(T_NEW, T_STRING, CT::T_NAMESPACE_OPERATOR))) {
                 // here can be added complete namespace scan
                 // this expression is differs from expected, resume
                 return $this->find($functionNameToSearch, $tokens, $openParenthesis, $end);

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

@@ -28,7 +28,6 @@ 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;
@@ -287,8 +286,6 @@ 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();
         $reporterFactory = ReporterFactory::create();
         $reporterFactory->registerBuiltInReporters();

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

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\Alias;
 
 use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
@@ -56,7 +57,7 @@ final class EchoToPrintFixer extends AbstractFixer
             $canBeConverted = true;
 
             for ($i = $nextTokenIndex; $i < $endTokenIndex; ++$i) {
-                if ($tokens[$i]->equalsAny(array('(', array(CT_ARRAY_SQUARE_BRACE_OPEN)))) {
+                if ($tokens[$i]->equalsAny(array('(', array(CT::T_ARRAY_SQUARE_BRACE_OPEN)))) {
                     $blockType = Tokens::detectBlockType($tokens[$i]);
                     $i = $tokens->findBlockEnd($blockType['type'], $i);
                 }

+ 2 - 1
src/Fixer/Alias/NoAliasFunctionsFixer.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\Alias;
 
 use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
@@ -74,7 +75,7 @@ final class NoAliasFunctionsFixer extends AbstractFixer
             if ($prevToken->isGivenKind(array(T_NS_SEPARATOR))) {
                 $twicePrevTokenIndex = $tokens->getPrevMeaningfulToken($prevTokenIndex);
                 $twicePrevToken = $tokens[$twicePrevTokenIndex];
-                if ($twicePrevToken->isGivenKind(array(T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, T_STRING, CT_NAMESPACE_OPERATOR))) {
+                if ($twicePrevToken->isGivenKind(array(T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, T_STRING, CT::T_NAMESPACE_OPERATOR))) {
                     continue;
                 }
             }

+ 4 - 3
src/Fixer/Alias/PowToExponentiationFixer.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\Alias;
 
 use PhpCsFixer\AbstractFunctionReferenceFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 
@@ -163,8 +164,8 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
     {
         static $allowedKinds = array(
             T_DNUMBER, T_LNUMBER, T_VARIABLE, T_STRING, T_OBJECT_OPERATOR, T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_CAST,
-            T_INT_CAST, T_INC, T_DEC, T_NS_SEPARATOR, T_WHITESPACE, T_DOUBLE_COLON, CT_NAMESPACE_OPERATOR, T_LINE,
-            T_COMMENT, T_DOC_COMMENT,
+            T_INT_CAST, T_INC, T_DEC, T_NS_SEPARATOR, T_WHITESPACE, T_DOUBLE_COLON, T_LINE, T_COMMENT, T_DOC_COMMENT,
+            CT::T_NAMESPACE_OPERATOR,
         );
 
         for ($i = $argumentStartIndex; $i <= $argumentEndIndex; ++$i) {
@@ -180,7 +181,7 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
 
             if ($tokens[$i]->equals('$')) {
                 $i = $tokens->getNextMeaningfulToken($i);
-                if ($tokens[$i]->isGivenKind(CT_DYNAMIC_VAR_BRACE_OPEN)) {
+                if ($tokens[$i]->isGivenKind(CT::T_DYNAMIC_VAR_BRACE_OPEN)) {
                     $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE, $i);
 
                     continue;

+ 3 - 2
src/Fixer/ArrayNotation/LongArraySyntaxFixer.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\ArrayNotation;
 
 use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 
@@ -26,7 +27,7 @@ final class LongArraySyntaxFixer extends AbstractFixer
      */
     public function isCandidate(Tokens $tokens)
     {
-        return $tokens->isTokenKindFound(CT_ARRAY_SQUARE_BRACE_OPEN);
+        return $tokens->isTokenKindFound(CT::T_ARRAY_SQUARE_BRACE_OPEN);
     }
 
     /**
@@ -37,7 +38,7 @@ final class LongArraySyntaxFixer extends AbstractFixer
         for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
             $token = $tokens[$index];
 
-            if (!$token->isGivenKind(CT_ARRAY_SQUARE_BRACE_OPEN)) {
+            if (!$token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
                 continue;
             }
 

+ 2 - 1
src/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixer.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\ArrayNotation;
 
 use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
 
@@ -27,7 +28,7 @@ final class NoTrailingCommaInSinglelineArrayFixer extends AbstractFixer
      */
     public function isCandidate(Tokens $tokens)
     {
-        return $tokens->isAnyTokenKindsFound(array(T_ARRAY, CT_ARRAY_SQUARE_BRACE_OPEN));
+        return $tokens->isAnyTokenKindsFound(array(T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN));
     }
 
     /**

+ 5 - 4
src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\ArrayNotation;
 
 use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
@@ -25,7 +26,7 @@ final class NoWhitespaceBeforeCommaInArrayFixer extends AbstractFixer
      */
     public function isCandidate(Tokens $tokens)
     {
-        return $tokens->isAnyTokenKindsFound(array(T_ARRAY, CT_ARRAY_SQUARE_BRACE_OPEN));
+        return $tokens->isAnyTokenKindsFound(array(T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN));
     }
 
     /**
@@ -34,7 +35,7 @@ final class NoWhitespaceBeforeCommaInArrayFixer extends AbstractFixer
     public function fix(\SplFileInfo $file, Tokens $tokens)
     {
         for ($index = $tokens->count() - 1; $index >= 0; --$index) {
-            if ($tokens[$index]->isGivenKind(array(T_ARRAY, CT_ARRAY_SQUARE_BRACE_OPEN))) {
+            if ($tokens[$index]->isGivenKind(array(T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN))) {
                 $this->fixSpacing($index, $tokens);
             }
         }
@@ -56,7 +57,7 @@ final class NoWhitespaceBeforeCommaInArrayFixer extends AbstractFixer
      */
     private function fixSpacing($index, Tokens $tokens)
     {
-        if ($tokens[$index]->isGivenKind(CT_ARRAY_SQUARE_BRACE_OPEN)) {
+        if ($tokens[$index]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
             $startIndex = $index;
             $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
         } else {
@@ -91,7 +92,7 @@ final class NoWhitespaceBeforeCommaInArrayFixer extends AbstractFixer
         if ($tokens[$index]->equals(')')) {
             $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index, false);
             $startIndex = $tokens->getPrevMeaningfulToken($startIndex);
-            if (!$tokens[$startIndex]->isGivenKind(array(T_ARRAY, CT_ARRAY_SQUARE_BRACE_OPEN))) {
+            if (!$tokens[$startIndex]->isGivenKind(array(T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN))) {
                 return $startIndex;
             }
         }

+ 4 - 3
src/Fixer/ArrayNotation/NormalizeIndexBraceFixer.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\ArrayNotation;
 
 use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 
@@ -26,7 +27,7 @@ final class NormalizeIndexBraceFixer extends AbstractFixer
      */
     public function isCandidate(Tokens $tokens)
     {
-        return $tokens->isTokenKindFound(CT_ARRAY_INDEX_CURLY_BRACE_OPEN);
+        return $tokens->isTokenKindFound(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN);
     }
 
     /**
@@ -35,9 +36,9 @@ final class NormalizeIndexBraceFixer extends AbstractFixer
     public function fix(\SplFileInfo $file, Tokens $tokens)
     {
         foreach ($tokens as $index => $token) {
-            if ($token->isGivenKind(CT_ARRAY_INDEX_CURLY_BRACE_OPEN)) {
+            if ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN)) {
                 $tokens->overrideAt($index, new Token('['));
-            } elseif ($token->isGivenKind(CT_ARRAY_INDEX_CURLY_BRACE_CLOSE)) {
+            } elseif ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE)) {
                 $tokens->overrideAt($index, new Token(']'));
             }
         }

+ 3 - 2
src/Fixer/ArrayNotation/ShortArraySyntaxFixer.php

@@ -13,6 +13,7 @@
 namespace PhpCsFixer\Fixer\ArrayNotation;
 
 use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
@@ -42,8 +43,8 @@ final class ShortArraySyntaxFixer extends AbstractFixer
             $openIndex = $tokens->getNextTokenOfKind($index, array('('));
             $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
 
-            $tokens->overrideAt($openIndex, array(CT_ARRAY_SQUARE_BRACE_OPEN, '['));
-            $tokens->overrideAt($closeIndex, array(CT_ARRAY_SQUARE_BRACE_CLOSE, ']'));
+            $tokens->overrideAt($openIndex, array(CT::T_ARRAY_SQUARE_BRACE_OPEN, '['));
+            $tokens->overrideAt($closeIndex, array(CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']'));
 
             $tokens->clearTokenAndMergeSurroundingWhitespace($index);
         }

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