Skip to content

Commit 41e1c1d

Browse files
committed
WIP refactored interface parsing into getInterfaces() method
1 parent d795bda commit 41e1c1d

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/CodeCoverage/Util/Tokenizer.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@ private function getParent(array $tokens, $i) {
106106
return $parent;
107107
}
108108

109+
private function getInterfaces(array $tokens, $i) {
110+
$interfaces = false;
111+
if (isset($tokens[$i + 4]) && $this->tid($tokens[$i + 4]) === T_IMPLEMENTS ||
112+
isset($tokens[$i + 8]) && $this->tid($tokens[$i + 8]) === T_IMPLEMENTS) {
113+
if ($this->tid($tokens[$i + 4]) === T_IMPLEMENTS) {
114+
$ii = $i + 3;
115+
} else {
116+
$ii = $i + 7;
117+
}
118+
119+
while (!$this->tclass($tokens[$ii+1]) === 'PHP_Token_OPEN_CURLY') {
120+
$ii++;
121+
122+
if ($this->tconst($tokens[$ii]) === T_STRING) {
123+
$interfaces[] = (string)$tokens[$ii];
124+
}
125+
}
126+
}
127+
128+
return $interfaces;
129+
}
130+
109131
public function tokenize() {
110132
$sourceCode = file_get_contents($this->filename);
111133
$tokens = token_get_all($sourceCode);
@@ -131,28 +153,10 @@ public function tokenize() {
131153

132154
case 'PHP_Token_CLASS':
133155
case 'PHP_Token_TRAIT':
134-
$interfaces = false;
135-
if (isset($tokens[$i + 4]) && $this->tid($tokens[$i + 4]) === T_IMPLEMENTS ||
136-
isset($tokens[$i + 8]) && $this->tid($tokens[$i + 8]) === T_IMPLEMENTS) {
137-
if ($this->tid($tokens[$i + 4]) === T_IMPLEMENTS) {
138-
$ii = $i + 3;
139-
} else {
140-
$ii = $i + 7;
141-
}
142-
143-
while (!$this->tclass($tokens[$ii+1]) === 'PHP_Token_OPEN_CURLY') {
144-
$ii++;
145-
146-
if ($this->tconst($tokens[$ii]) === T_STRING) {
147-
$interfaces[] = (string)$tokens[$ii];
148-
}
149-
}
150-
}
151-
152156
$tmp = array(
153157
'methods' => array(),
154158
'parent' => $this->getParent($tokens, $i),
155-
'interfaces'=> $interfaces,
159+
'interfaces'=> $this->getInterfaces($tokens, $i),
156160
'keywords' => $this->getKeywords($tokens, $i),
157161
'docblock' => $token->getDocblock(),
158162
'startLine' => $token->getLine(),

0 commit comments

Comments
 (0)