| 556 |
556 |
|
| 557 |
557 |
$this->assertSame($expected, $actual); |
| 558 |
558 |
} |
|
559 |
+ |
|
560 |
+ /** |
|
561 |
+ * testTokenizerSubstitutesDollarCurlyOpenWithTwoSeparateTokens |
|
562 |
+ * |
|
563 |
+ * @return void |
|
564 |
+ * @covers PHP_Depend_Tokenizer_Internal |
|
565 |
+ * @group pdepend |
|
566 |
+ * @group pdepend::tokenizer |
|
567 |
+ * @group unittest |
|
568 |
+ */ |
|
569 |
+ public function testTokenizerSubstitutesDollarCurlyOpenWithTwoSeparateTokens() |
|
570 |
+ { |
|
571 |
+ $tokenizer = new PHP_Depend_Tokenizer_Internal(); |
|
572 |
+ $tokenizer->setSourceFile( |
|
573 |
+ self::createCodeResourceURI('tokenizer/' . __FUNCTION__ . '.php') |
|
574 |
+ ); |
|
575 |
+ |
|
576 |
+ $actual = array(); |
|
577 |
+ while (is_object($token = $tokenizer->next())) { |
|
578 |
+ $actual[] = array($token->type, $token->startColumn, $token->endColumn); |
|
579 |
+ } |
|
580 |
+ |
|
581 |
+ $expected = array( |
|
582 |
+ array(PHP_Depend_ConstantsI::T_OPEN_TAG, 1, 5), |
|
583 |
+ array(PHP_Depend_ConstantsI::T_DOLLAR, 1, 1), |
|
584 |
+ array(PHP_Depend_ConstantsI::T_CURLY_BRACE_OPEN, 2, 2), |
|
585 |
+ array(PHP_Depend_ConstantsI::T_VARIABLE, 3, 6), |
|
586 |
+ array(PHP_Depend_ConstantsI::T_CONCAT, 8, 8), |
|
587 |
+ array(PHP_Depend_ConstantsI::T_VARIABLE, 10, 13), |
|
588 |
+ array(PHP_Depend_ConstantsI::T_CURLY_BRACE_CLOSE, 14, 14), |
|
589 |
+ array(PHP_Depend_ConstantsI::T_SEMICOLON, 15, 15), |
|
590 |
+ ); |
|
591 |
+ |
|
592 |
+ $this->assertEquals($expected, $actual); |
|
593 |
+ } |
| 559 |
594 |
} |
| 422 |
426 |
} |
| 423 |
427 |
|
| 424 |
428 |
/** |
|
429 |
+ * This method takes an array of tokens returned by <b>token_get_all()</b> |
|
430 |
+ * and substitutes some of the tokens with those required by PHP_Depend's |
|
431 |
+ * parser implementation. |
|
432 |
+ * |
|
433 |
+ * @param array(array) $tokens Unprepared array of php tokens. |
|
434 |
+ * |
|
435 |
+ * @return array(array) |
|
436 |
+ */ |
|
437 |
+ private function _substituteTokens(array $tokens) |
|
438 |
+ { |
|
439 |
+ $result = array(); |
|
440 |
+ foreach ($tokens as $token) { |
|
441 |
+ $temp = (array) $token; |
|
442 |
+ $temp = $temp[0]; |
|
443 |
+ if (isset(self::$substituteTokens[$temp])) { |
|
444 |
+ foreach (self::$substituteTokens[$temp] as $token) { |
|
445 |
+ $result[] = $token; |
|
446 |
+ } |
|
447 |
+ } else { |
|
448 |
+ $result[] = $token; |
|
449 |
+ } |
|
450 |
+ } |
|
451 |
+ return $result; |
|
452 |
+ } |
|
453 |
+ |
|
454 |
+ /** |
| 425 |
455 |
* Tokenizes the content of the source file with {@link token_get_all()} and |
| 426 |
456 |
* filters this token stream. |
| 427 |
457 |
* |
| 443 |
473 |
); |
| 444 |
474 |
|
| 445 |
475 |
if (version_compare(phpversion(), '5.3.0alpha3') < 0) { |
| 446 |
|
- $tempTokens = PHP_Depend_Tokenizer_PHP53NamespaceHelper::tokenize($source); |
|
476 |
+ $tokens = PHP_Depend_Tokenizer_PHP53NamespaceHelper::tokenize($source); |
| 447 |
477 |
} else { |
| 448 |
|
- $tempTokens = token_get_all($source); |
|
478 |
+ $tokens = token_get_all($source); |
| 449 |
479 |
} |
| 450 |
480 |
|
| 451 |
|
- $tokens = array(); |
| 452 |
|
- foreach ($tempTokens as $tempToken) { |
| 453 |
|
- $temp = (array) $tempToken; |
| 454 |
|
- $temp = $temp[0]; |
| 455 |
|
- if (isset(self::$substitutes[$temp])) { |
| 456 |
|
- foreach (self::$substitutes[$temp] as $token) { |
| 457 |
|
- $tokens[] = $token; |
| 458 |
|
- } |
| 459 |
|
- } else { |
| 460 |
|
- $tokens[] = $tempToken; |
| 461 |
|
- } |
| 462 |
|
- } |
|
481 |
+ $tokens = $this->_substituteTokens($tokens); |
| 463 |
482 |
|
| 464 |
|
- |
| 465 |
|
- reset($tokens); |
| 466 |
|
- |
| 467 |
483 |
// Is the current token between an opening and a closing php tag? |
| 468 |
484 |
$inTag = false; |
| 469 |
485 |
|