Skip to content

Commit d795bda

Browse files
committed
WIP refactored parent class parsing into getParent() method
1 parent a1faf6b commit d795bda

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/CodeCoverage/Util/Tokenizer.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ private function getKeywords(array $tokens, $idx) {
9191
return implode(',', $keywords);
9292
}
9393

94+
private function getParent(array $tokens, $i) {
95+
$parent = false;
96+
if ($this->tconst($tokens[$i+4]) === T_EXTENDS) {
97+
$ci = $i + 6;
98+
$className = (string)$tokens[$ci];
99+
100+
while (isset($tokens[$ci+1]) && !($this->tconst($tokens[$ci+1]) === T_WHITESPACE)) {
101+
$className .= (string)$tokens[++$ci];
102+
}
103+
104+
$parent = $className;
105+
}
106+
return $parent;
107+
}
108+
94109
public function tokenize() {
95110
$sourceCode = file_get_contents($this->filename);
96111
$tokens = token_get_all($sourceCode);
@@ -116,18 +131,6 @@ public function tokenize() {
116131

117132
case 'PHP_Token_CLASS':
118133
case 'PHP_Token_TRAIT':
119-
$parent = false;
120-
if ($this->tconst($tokens[$i+4]) === T_EXTENDS) {
121-
$ci = $i + 6;
122-
$className = (string)$tokens[$ci];
123-
124-
while (isset($tokens[$ci+1]) && !($this->tconst($tokens[$ci+1]) === T_WHITESPACE)) {
125-
$className .= (string)$tokens[++$ci];
126-
}
127-
128-
$parent = $className;
129-
}
130-
131134
$interfaces = false;
132135
if (isset($tokens[$i + 4]) && $this->tid($tokens[$i + 4]) === T_IMPLEMENTS ||
133136
isset($tokens[$i + 8]) && $this->tid($tokens[$i + 8]) === T_IMPLEMENTS) {
@@ -148,7 +151,7 @@ public function tokenize() {
148151

149152
$tmp = array(
150153
'methods' => array(),
151-
'parent' => $parent,
154+
'parent' => $this->getParent($tokens, $i),
152155
'interfaces'=> $interfaces,
153156
'keywords' => $this->getKeywords($tokens, $i),
154157
'docblock' => $token->getDocblock(),

0 commit comments

Comments
 (0)