Skip to content

Commit 0515fb8

Browse files
committed
WIP refactored visibility class parsing into getVisibility() method
1 parent ebb47fc commit 0515fb8

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/CodeCoverage/Util/Tokenizer.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ private function getInterfaces(array $tokens, $i) {
135135
return $interfaces;
136136
}
137137

138+
/**
139+
* @return string
140+
*/
141+
private function getVisibility(array $tokens, $idx)
142+
{
143+
for ($i = $idx - 2; $i > $idx - 7; $i -= 2) {
144+
if (isset($tokens[$i])) {
145+
$tconst = $this->tconst($tokens[$i]);
146+
147+
if ($tconst === T_PRIVATE) {
148+
return "private";
149+
} else if($tconst === T_PROTECTED) {
150+
return "protected";
151+
}else if ($tconst === T_PUBLIC) {
152+
return "public";
153+
}
154+
155+
if (!($tconst === T_STATIC || $tconst === T_FINAL || $tconst === T_ABSTRACT)) {
156+
// no keywords; stop visibility search
157+
break;
158+
}
159+
}
160+
}
161+
}
162+
138163
public function tokenize() {
139164
$sourceCode = file_get_contents($this->filename);
140165
$tokens = token_get_all($sourceCode);
@@ -206,7 +231,7 @@ public function tokenize() {
206231
$tmp = array(
207232
'docblock' => $token->getDocblock(),
208233
'keywords' => $this->getKeywords($tokens, $i),
209-
'visibility'=> $token->getVisibility(),
234+
'visibility'=> $this->getVisibility($tokens, $i),
210235
'signature' => $token->getSignature(),
211236
'startLine' => $this->tline($token),
212237
'endLine' => $token->getEndLine(),

0 commit comments

Comments
 (0)