Skip to content

Commit 3691ad8

Browse files
committed
WIP inline Class/Trait getParent()
1 parent 91f6232 commit 3691ad8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/CodeCoverage/Util/Tokenizer.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public function __construct($filename) {
4545
$this->filename = $filename;
4646
}
4747

48+
private function tconst($token) {
49+
if (is_array($token)) {
50+
return $token[0];
51+
}
52+
return null;
53+
}
54+
4855
public function tokenize() {
4956
$sourceCode = file_get_contents($this->filename);
5057
$tokens = token_get_all($sourceCode);
@@ -70,9 +77,21 @@ public function tokenize() {
7077

7178
case 'PHP_Token_CLASS':
7279
case 'PHP_Token_TRAIT':
80+
$parent = false;
81+
if ($this->tconst($tokens[$i+4]) === T_EXTENDS) {
82+
$ci = $i + 6;
83+
$className = (string)$tokens[$ci];
84+
85+
while (isset($tokens[$ci+1]) && !($this->tconst($tokens[$ci+1]) === T_WHITESPACE)) {
86+
$className .= (string)$tokens[++$ci];
87+
}
88+
89+
$parent = $className;
90+
}
91+
7392
$tmp = array(
7493
'methods' => array(),
75-
'parent' => $token->getParent(),
94+
'parent' => $parent,
7695
'interfaces'=> $token->getInterfaces(),
7796
'keywords' => $token->getKeywords(),
7897
'docblock' => $token->getDocblock(),

0 commit comments

Comments
 (0)