Skip to content

Commit 41b2993

Browse files
committed
WIP refactored ccn parsing into getCCN() method
1 parent c9a5eb2 commit 41b2993

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/CodeCoverage/Util/Tokenizer.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,41 @@ private function getSignature(array $tokens, $idx)
397397
return $signature;
398398
}
399399

400+
/**
401+
* @return integer
402+
*/
403+
private function getCCN($tokens, $idx)
404+
{
405+
$ccn = 1;
406+
$end = $this->getEndTokenId($tokens, $idx);
407+
408+
$ccnTokens = array(
409+
T_IF,
410+
T_ELSEIF,
411+
T_FOR,
412+
T_FOREACH,
413+
T_WHILE,
414+
T_CASE,
415+
T_CATCH,
416+
T_BOOLEAN_AND,
417+
T_LOGICAL_AND,
418+
T_BOOLEAN_OR,
419+
T_LOGICAL_OR
420+
);
421+
for ($i = $idx; $i <= $end; $i++) {
422+
$tconst = $this->tconst($tokens[$i]);
423+
if (in_array($tconst, $ccnTokens)) {
424+
$ccn++;
425+
}
426+
$tclass = $this->tclass($tokens[$i]);
427+
if ($tclass === 'PHP_Token_QUESTION_MARK') {
428+
$ccn++;
429+
}
430+
}
431+
432+
return $ccn;
433+
}
434+
400435
public function tokenize() {
401436
$sourceCode = file_get_contents($this->filename);
402437
$tokens = token_get_all($sourceCode);
@@ -474,7 +509,7 @@ public function tokenize() {
474509
'signature' => $this->getSignature($tokens, $i),
475510
'startLine' => $this->tline($token),
476511
'endLine' => $this->getEndLine($tokens, $i),
477-
'ccn' => $token->getCCN(),
512+
'ccn' => $this->getCCN($tokens, $i),
478513
'file' => $this->filename
479514
);
480515

0 commit comments

Comments
 (0)