$root = $this->trees[$path]->getRootNode();
+ $root->buildSelectCache();
+ $root->buildTokenCache();
+
$this->lintUseOfThisInStaticMethods($root);
$this->lintDynamicDefines($root);
$this->lintSurpriseConstructors($root);
protected function lintHashComments($root) {
- $tokens = $root->getTokens();
- foreach ($tokens as $token) {
- if ($token->getTypeName() == 'T_COMMENT') {
- $value = $token->getValue();
- if ($value[0] == '#') {
- $this->raiseLintAtOffset(
- $token->getOffset(),
- self::LINT_COMMENT_STYLE,
- 'Use "//" single-line comments, not "#".',
- '#',
- '//');
- }
+ foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
+ $value = $comment->getValue();
+ if ($value[0] != '#') {
+ continue;
}
+
+ $this->raiseLintAtOffset(
+ $comment->getOffset(),
+ self::LINT_COMMENT_STYLE,
+ 'Use "//" single-line comments, not "#".',
+ '#',
+ '//');
}
}
break;
}
}
- foreach ($tokens as $token) {
- if ($token->getTypeName() == 'T_CLOSE_TAG') {
- $this->raiseLintAtToken(
- $token,
- self::LINT_PHP_CLOSE_TAG,
- 'Do not use the PHP closing tag, "?>".');
- }
+
+ foreach ($root->selectTokensOfType('T_CLOSE_TAG') as $token) {
+ $this->raiseLintAtToken(
+ $token,
+ self::LINT_PHP_CLOSE_TAG,
+ 'Do not use the PHP closing tag, "?>".');
}
}
}
protected function lintTODOComments($root) {
- $tokens = $root->getTokens();
- foreach ($tokens as $token) {
- if (!$token->isComment()) {
- continue;
- }
+ $comments = $root->selectTokensOfType('T_COMMENT') +
+ $root->selectTokensOfType('T_DOC_COMMENT');
+ foreach ($comments as $token) {
$value = $token->getValue();
$matches = null;
$preg = preg_match_all(