Skip to content

Commit a1faf6b

Browse files
committed
WIP inline Token->getKeywords()
1 parent a3f24fc commit a1faf6b

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/CodeCoverage/Util/Tokenizer.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,33 @@ private function tclass($token) {
6464
}
6565
}
6666

67+
/**
68+
* @return string
69+
*/
70+
private function getKeywords(array $tokens, $idx) {
71+
$keywords = array();
72+
73+
for ($i = $idx - 2; $i > $idx - 7; $i -= 2) {
74+
if (isset($tokens[$i])) {
75+
$tconst = $this->tconst($tokens[$i]);
76+
77+
if ($tconst === T_PRIVATE || $tconst === T_PROTECTED || $tconst === T_PUBLIC) {
78+
continue;
79+
}
80+
81+
if ($tconst === T_STATIC) {
82+
$keywords[] = 'static';
83+
} else if ($tconst === T_FINAL) {
84+
$keywords[] = 'final';
85+
} else if ($tconst === T_ABSTRACT) {
86+
$keywords[] = 'abstract';
87+
}
88+
}
89+
}
90+
91+
return implode(',', $keywords);
92+
}
93+
6794
public function tokenize() {
6895
$sourceCode = file_get_contents($this->filename);
6996
$tokens = token_get_all($sourceCode);
@@ -123,7 +150,7 @@ public function tokenize() {
123150
'methods' => array(),
124151
'parent' => $parent,
125152
'interfaces'=> $interfaces,
126-
'keywords' => $token->getKeywords(),
153+
'keywords' => $this->getKeywords($tokens, $i),
127154
'docblock' => $token->getDocblock(),
128155
'startLine' => $token->getLine(),
129156
'endLine' => $token->getEndLine(),
@@ -146,7 +173,7 @@ public function tokenize() {
146173
$name = $token->getName();
147174
$tmp = array(
148175
'docblock' => $token->getDocblock(),
149-
'keywords' => $token->getKeywords(),
176+
'keywords' => $this->getKeywords($tokens, $i),
150177
'visibility'=> $token->getVisibility(),
151178
'signature' => $token->getSignature(),
152179
'startLine' => $token->getLine(),

0 commit comments

Comments
 (0)