Skip to content

Commit d10990d

Browse files
committed
fixed undefined var warnings
1 parent 638c005 commit d10990d

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/CodeCoverage/Report/Node/File.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ protected function calculateStatistics()
354354
$tokenizer = new PHP_CodeCoverage_Util_Tokenizer($this->getPath());
355355
$tokenizer->tokenize();
356356

357-
$classes = $tokenizer->getClasses();
358-
$traits = $tokenizer->getTraits();
359-
$functions = $tokenizer->getFunctions();
357+
$this->processClasses($tokenizer->getClasses());
358+
$this->processTraits($tokenizer->getTraits());
359+
$this->processFunctions($tokenizer->getFunctions());
360360
$this->linesOfCode = $tokenizer->getLinesOfCode();
361361

362362
for ($lineNumber = 1; $lineNumber <= $this->linesOfCode['loc']; $lineNumber++) {

src/CodeCoverage/Util/Tokenizer.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function tname(array $tokens, $idx) {
8888
if ($tconst === T_STRING) {
8989
$name = $this->tstring($token);
9090
break;
91-
} elseif ($tconst === T_STRING && $tclass === 'PHP_Token_AMPERSAND' && $this->tconst($tokens[$i+1]) === T_STRING) {
91+
} elseif ($tclass === 'PHP_Token_AMPERSAND' && $this->tconst($tokens[$i+1]) === T_STRING) {
9292
$name = $this->tstring($tokens[$i+1]);
9393
break;
9494
} elseif ($tclass === 'PHP_Token_OPEN_BRACKET') {
@@ -105,7 +105,7 @@ private function tname(array $tokens, $idx) {
105105
break;
106106
}
107107

108-
if ($tconst === T_INTERFACE) {
108+
if ($tconst === T_INTERFACE || $tconst === T_CLASS || $tconst === T_TRAIT) {
109109
break;
110110
}
111111
}
@@ -114,7 +114,7 @@ private function tname(array $tokens, $idx) {
114114
return $name;
115115
}
116116

117-
if ($tconst === T_CLASS || $tconst === T_TRAIT) {
117+
if ($tconst === T_INTERFACE || $tconst === T_CLASS || $tconst === T_TRAIT) {
118118
return $this->tstring($tokens[$idx + 2]);
119119
}
120120

@@ -262,7 +262,7 @@ private function getDocblock(array $tokens, $idx) {
262262
continue;
263263
}
264264

265-
if ($line < $currentLineNumber && $tconst === T_DOC_COMMENT) {
265+
if ($line < $currentLineNumber && $tconst !== T_DOC_COMMENT) {
266266
break;
267267
}
268268

@@ -390,7 +390,7 @@ private function getSignature(array $tokens, $idx)
390390
$i = $idx + 2;
391391
}
392392

393-
while (isset($tokens[$i]) && $tclass = $this->tclass($tokens[$i]) &&
393+
while (isset($tokens[$i]) && ($tclass = $this->tclass($tokens[$i])) &&
394394
$tclass !== 'PHP_Token_OPEN_CURLY' &&
395395
$tclass !== 'PHP_Token_SEMICOLON') {
396396
$signature .= $this->tstring($tokens[$i++]);
@@ -459,6 +459,12 @@ public function tokenize() {
459459
$line += $lines;
460460
}
461461

462+
$class = false;
463+
$classEndLine = false;
464+
$trait = false;
465+
$traitEndLine = false;
466+
$interface = false;
467+
$interfaceEndLine = false;
462468
$line = 1;
463469
for ($i = 0; $i < $numTokens; ++$i) {
464470
$token = $tokens[$i];
@@ -473,8 +479,27 @@ public function tokenize() {
473479
$tokenClass = self::$customTokens[$token];
474480
}
475481

482+
$lines = substr_count($text, "\n");
483+
$line += $lines;
484+
476485
switch ($tokenClass) {
477486
case 'PHP_Token_HALT_COMPILER':
487+
break 2;
488+
489+
case 'PHP_Token_INTERFACE':
490+
$interface = $this->tname($tokens, $i);
491+
$interfaceEndLine = $this->getEndLine($tokens, $i);
492+
493+
$this->interfaces[$interface] = array(
494+
'methods' => array(),
495+
'parent' => $this->getParent($tokens, $i),
496+
'keywords' => $this->getKeywords($tokens, $i),
497+
'docblock' => $this->getDocblock($tokens, $i),
498+
'startLine' => $this->tline($i),
499+
'endLine' => $interfaceEndLine,
500+
'package' => $this->getPackage($tokens, $i),
501+
'file' => $this->filename
502+
);
478503
break;
479504

480505
case 'PHP_Token_CLASS':
@@ -493,19 +518,20 @@ public function tokenize() {
493518
'file' => $this->filename
494519
);
495520

496-
if ($this->tconst($token) === T_CLASS) {
497-
$class = $this->tname($tokens, $i + 2);
521+
$tclass = $this->tclass($token);
522+
if ($tclass === 'PHP_Token_CLASS') {
523+
$class = $this->tname($tokens, $i);
498524
$classEndLine = $endLine;
499525
$this->classes[$class] = $tmp;
500526
} else {
501-
$trait = $this->tname($tokens, $i + 2);
527+
$trait = $this->tname($tokens, $i);
502528
$traitEndLine = $endLine;
503529
$this->traits[$trait] = $tmp;
504530
}
505531
break;
506532

507533
case 'PHP_Token_FUNCTION':
508-
$tname = $this->tname($tokens, $idx);
534+
$tname = $this->tname($tokens, $i);
509535
$tmp = array(
510536
'docblock' => $this->getDocblock($tokens, $i),
511537
'keywords' => $this->getKeywords($tokens, $i),
@@ -547,14 +573,10 @@ public function tokenize() {
547573
$this->linesOfCode['cloc'] += $lines + 1;
548574
break;
549575
}
550-
551-
$lines = substr_count($text, "\n");
552-
$line += $lines;
553576
}
554577

555578
$this->linesOfCode['loc'] = substr_count($sourceCode, "\n");
556-
$this->linesOfCode['ncloc'] = $this->linesOfCode['loc'] -
557-
$this->linesOfCode['cloc'];
579+
$this->linesOfCode['ncloc'] = $this->linesOfCode['loc'] - $this->linesOfCode['cloc'];
558580
}
559581

560582
public function getLinesOfCode() {

0 commit comments

Comments
 (0)