コード例 #1
0
 private function fixAssertSame(Tokens $tokens, $index)
 {
     static $map = array('false' => 'assertFalse', 'null' => 'assertNull', 'true' => 'assertTrue');
     $sequence = $tokens->findSequence(array(array(T_VARIABLE, '$this'), array(T_OBJECT_OPERATOR, '->'), array(T_STRING, 'assertSame'), '('), $index);
     if (null === $sequence) {
         return;
     }
     $sequenceIndexes = array_keys($sequence);
     $sequenceIndexes[4] = $tokens->getNextMeaningfulToken($sequenceIndexes[3]);
     $firstParameterToken = $tokens[$sequenceIndexes[4]];
     if (!$firstParameterToken->isNativeConstant()) {
         return;
     }
     $sequenceIndexes[5] = $tokens->getNextNonWhitespace($sequenceIndexes[4]);
     $tokens[$sequenceIndexes[2]]->setContent($map[$firstParameterToken->getContent()]);
     $tokens->clearRange($sequenceIndexes[4], $tokens->getNextNonWhitespace($sequenceIndexes[5]) - 1);
     return $sequenceIndexes[5];
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         $token = $tokens[$index];
         if (!$token->isGivenKind(T_LIST)) {
             continue;
         }
         $openIndex = $tokens->getNextMeaningfulToken($index);
         $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
         $markIndex = null;
         $prevIndex = $tokens->getPrevNonWhitespace($closeIndex);
         while ($tokens[$prevIndex]->equals(',')) {
             $markIndex = $prevIndex;
             $prevIndex = $tokens->getPrevNonWhitespace($prevIndex);
         }
         if (null !== $markIndex) {
             $tokens->clearRange($tokens->getPrevNonWhitespace($markIndex) + 1, $closeIndex - 1);
         }
     }
 }
コード例 #3
0
 private function fixAssert(array $map, Tokens $tokens, $index, $method)
 {
     $sequence = $tokens->findSequence(array(array(T_VARIABLE, '$this'), array(T_OBJECT_OPERATOR, '->'), array(T_STRING, $method), '('), $index);
     if (null === $sequence) {
         return;
     }
     $sequenceIndexes = array_keys($sequence);
     $sequenceIndexes[4] = $tokens->getNextMeaningfulToken($sequenceIndexes[3]);
     $firstParameterToken = $tokens[$sequenceIndexes[4]];
     if (!$firstParameterToken->isNativeConstant()) {
         return;
     }
     $sequenceIndexes[5] = $tokens->getNextMeaningfulToken($sequenceIndexes[4]);
     if (!$tokens[$sequenceIndexes[5]]->equals(',')) {
         return;
     }
     $tokens[$sequenceIndexes[2]]->setContent($map[$firstParameterToken->getContent()]);
     $tokens->clearRange($sequenceIndexes[4], $tokens->getNextNonWhitespace($sequenceIndexes[5]) - 1);
     return $sequenceIndexes[5];
 }
コード例 #4
0
 /**
  * Replace the header comment at the given index.
  *
  * @param Tokens $tokens
  * @param int    $oldHeaderIndex
  */
 private function replaceHeaderComment(Tokens $tokens, $oldHeaderIndex)
 {
     if ('' === $this->headerComment) {
         if ($oldHeaderIndex) {
             $tokens->clearRange($oldHeaderIndex, $oldHeaderIndex + 1);
         }
         return;
     }
     $headCommentTokens = array(new Token(array(T_WHITESPACE, "\n")), new Token(array(T_COMMENT, $this->headerComment)), new Token(array(T_WHITESPACE, "\n\n")));
     $newHeaderIndex = null !== $oldHeaderIndex ? $oldHeaderIndex + 1 : $this->findHeaderCommentInsertionIndex($tokens) - 1;
     $tokens->overrideRange(1, $newHeaderIndex, $headCommentTokens);
 }
コード例 #5
0
 /**
  * @param Tokens $tokens
  * @param int    $classIndex
  */
 private function replaceClassKeyword(Tokens $tokens, $classIndex)
 {
     $classEndIndex = $classIndex - 2;
     $classBeginIndex = $classEndIndex;
     while ($tokens[--$classBeginIndex]->isGivenKind(array(T_NS_SEPARATOR, T_STRING))) {
     }
     ++$classBeginIndex;
     $classString = $tokens->generatePartialCode($classBeginIndex, $classEndIndex);
     $classImport = false;
     foreach ($this->imports as $alias => $import) {
         if ($classString === $alias) {
             $classImport = $import;
             break;
         }
         $classStringArray = explode('\\', $classString);
         $namespaceToTest = $classStringArray[0];
         if (0 === strcmp($namespaceToTest, substr($import, -strlen($namespaceToTest)))) {
             $classImport = $import;
             break;
         }
     }
     $tokens->clearRange($classBeginIndex, $classIndex);
     $tokens->insertAt($classBeginIndex, new Token(array(T_CONSTANT_ENCAPSED_STRING, "'" . $this->makeClassFQN($classImport, $classString) . "'")));
 }