Skip to content

Commit c9a5eb2

Browse files
committed
WIP refactored signature parsing into getSignature() method
1 parent 5b5e75d commit c9a5eb2

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
@@ -372,6 +372,31 @@ private function arrayToName(array $parts, $join = '\\')
372372
return $result;
373373
}
374374

375+
/**
376+
* @return string
377+
*/
378+
private function getSignature(array $tokens, $idx)
379+
{
380+
$token = $tokens[$idx];
381+
if ($this->tname($token) == 'anonymous function') {
382+
$signature = 'anonymous function';
383+
$i = $idx + 1;
384+
} else {
385+
$signature = '';
386+
$i = $idx + 2;
387+
}
388+
389+
while (isset($tokens[$i]) && $tclass = $this->tclass($tokens[$i]) &&
390+
$tclass !== 'PHP_Token_OPEN_CURLY' &&
391+
$tclass !== 'PHP_Token_SEMICOLON') {
392+
$signature .= $tokens[$i++];
393+
}
394+
395+
$signature = trim($signature);
396+
397+
return $signature;
398+
}
399+
375400
public function tokenize() {
376401
$sourceCode = file_get_contents($this->filename);
377402
$tokens = token_get_all($sourceCode);
@@ -446,7 +471,7 @@ public function tokenize() {
446471
'docblock' => $this->getDocblock($tokens, $i),
447472
'keywords' => $this->getKeywords($tokens, $i),
448473
'visibility'=> $this->getVisibility($tokens, $i),
449-
'signature' => $token->getSignature(),
474+
'signature' => $this->getSignature($tokens, $i),
450475
'startLine' => $this->tline($token),
451476
'endLine' => $this->getEndLine($tokens, $i),
452477
'ccn' => $token->getCCN(),

0 commit comments

Comments
 (0)