Skip to content

Commit e7fe396

Browse files
Implement PHP_CodeCoverage_Report_Node::getLinesOfCode().
1 parent 82dddc5 commit e7fe396

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

PHP/CodeCoverage/Report/Node.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ abstract public function getTraits();
173173
*/
174174
abstract public function getFunctions();
175175

176+
/**
177+
* Returns the LOC/CLOC/NCLOC of this node.
178+
*
179+
* @return array
180+
*/
181+
abstract public function getLinesOfCode();
182+
176183
/**
177184
* Returns the number of executable lines.
178185
*

PHP/CodeCoverage/Report/Node/Directory.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class PHP_CodeCoverage_Report_Node_Directory extends PHP_CodeCoverage_Report_Nod
8787
*/
8888
protected $functions;
8989

90+
/**
91+
* @var array
92+
*/
93+
protected $linesOfCode = NULL;
94+
9095
/**
9196
* @var integer
9297
*/
@@ -284,6 +289,28 @@ public function getFunctions()
284289
return $this->functions;
285290
}
286291

292+
/**
293+
* Returns the LOC/CLOC/NCLOC of this node.
294+
*
295+
* @return array
296+
*/
297+
public function getLinesOfCode()
298+
{
299+
if ($this->linesOfCode === NULL) {
300+
$this->linesOfCode = array('loc' => 0, 'cloc' => 0, 'ncloc' => 0);
301+
302+
foreach ($this->children as $child) {
303+
$linesOfCode = $child->getLinesOfCode();
304+
305+
$this->linesOfCode['loc'] += $linesOfCode['loc'];
306+
$this->linesOfCode['cloc'] += $linesOfCode['cloc'];
307+
$this->linesOfCode['ncloc'] += $linesOfCode['ncloc'];
308+
}
309+
}
310+
311+
return $this->linesOfCode;
312+
}
313+
287314
/**
288315
* Returns the number of executable lines.
289316
*

PHP/CodeCoverage/Report/Node/File.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ class PHP_CodeCoverage_Report_Node_File extends PHP_CodeCoverage_Report_Node
106106
*/
107107
protected $functions = array();
108108

109+
/**
110+
* @var array
111+
*/
112+
protected $linesOfCode = array();
113+
109114
/**
110115
* @var integer
111116
*/
@@ -188,6 +193,16 @@ public function getFunctions()
188193
return $this->functions;
189194
}
190195

196+
/**
197+
* Returns the LOC/CLOC/NCLOC of this node.
198+
*
199+
* @return array
200+
*/
201+
public function getLinesOfCode()
202+
{
203+
return $this->linesOfCode;
204+
}
205+
191206
/**
192207
* Returns the number of executable lines.
193208
*
@@ -360,6 +375,7 @@ protected function calculateStatistics()
360375
$this->processClasses($tokens);
361376
$this->processTraits($tokens);
362377
$this->processFunctions($tokens);
378+
$this->linesOfCode = $tokens->getLinesOfCode();
363379
unset($tokens);
364380

365381
$max = count(file($this->getPath()));

0 commit comments

Comments
 (0)