Skip to content

Commit a03673e

Browse files
Refactor.
1 parent 8819813 commit a03673e

File tree

6 files changed

+24
-30
lines changed

6 files changed

+24
-30
lines changed

PHP/CodeCoverage/Report/Factory.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ public static function create(PHP_CodeCoverage $coverage)
6565
$files = $coverage->getData();
6666
$commonPath = PHP_CodeCoverage_Util::reducePaths($files);
6767
$root = new PHP_CodeCoverage_Report_Node_Directory(
68-
$commonPath, $commonPath, NULL
68+
$commonPath, NULL
6969
);
7070

7171
self::addItems(
7272
$root,
7373
PHP_CodeCoverage_Util::buildDirectoryStructure($files),
74-
$coverage->getTests(),
75-
$commonPath
74+
$coverage->getTests()
7675
);
7776

7877
return $root;
@@ -82,17 +81,16 @@ public static function create(PHP_CodeCoverage $coverage)
8281
* @param PHP_CodeCoverage_Report_Node_Directory $root
8382
* @param array $items
8483
* @param array $tests
85-
* @param string $commonPath
8684
*/
87-
protected static function addItems(PHP_CodeCoverage_Report_Node_Directory $root, array $items, array $tests, $commonPath)
85+
protected static function addItems(PHP_CodeCoverage_Report_Node_Directory $root, array $items, array $tests)
8886
{
8987
foreach ($items as $key => $value) {
9088
if (substr($key, -2) == '/f') {
9189
$key = substr($key, 0, -2);
92-
$root->addFile($key, $commonPath . $key, $value, $tests);
90+
$root->addFile($key, $value, $tests);
9391
} else {
94-
$child = $root->addDirectory($key, $commonPath . $key);
95-
self::addItems($child, $value, $tests, $commonPath);
92+
$child = $root->addDirectory($key);
93+
self::addItems($child, $value, $tests);
9694
}
9795
}
9896
}

PHP/CodeCoverage/Report/Node.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,11 @@ abstract class PHP_CodeCoverage_Report_Node implements Countable
7676
* Constructor.
7777
*
7878
* @param string $name
79-
* @param string $path
8079
* @param PHP_CodeCoverage_Report_Node $parent
8180
*/
82-
public function __construct($name, $path, PHP_CodeCoverage_Report_Node $parent = NULL)
81+
public function __construct($name, PHP_CodeCoverage_Report_Node $parent = NULL)
8382
{
8483
$this->name = $name;
85-
$this->path = $path;
8684
$this->parent = $parent;
8785
}
8886

@@ -99,6 +97,14 @@ public function getName()
9997
*/
10098
public function getPath()
10199
{
100+
if ($this->path === NULL) {
101+
if ($this->parent === NULL) {
102+
$this->path = $this->name;
103+
} else {
104+
$this->path = $this->parent->getPath() . '/' . $this->name;
105+
}
106+
}
107+
102108
return $this->path;
103109
}
104110

PHP/CodeCoverage/Report/Node/Directory.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,11 @@ public function getIterator()
182182
* Adds a new directory.
183183
*
184184
* @param string $name
185-
* @param string $path
186185
* @return PHP_CodeCoverage_Report_Node_Directory
187186
*/
188-
public function addDirectory($name, $path)
187+
public function addDirectory($name)
189188
{
190-
$directory = new PHP_CodeCoverage_Report_Node_Directory(
191-
$name, $path, $this
192-
);
189+
$directory = new PHP_CodeCoverage_Report_Node_Directory($name, $this);
193190

194191
$this->children[] = $directory;
195192
$this->directories[] = &$this->children[count($this->children) - 1];
@@ -201,16 +198,15 @@ public function addDirectory($name, $path)
201198
* Adds a new file.
202199
*
203200
* @param string $name
204-
* @param string $path
205201
* @param array $coverageData
206202
* @param array $testData
207203
* @return PHP_CodeCoverage_Report_Node_File
208204
* @throws RuntimeException
209205
*/
210-
public function addFile($name, $path, array $coverageData, array $testData)
206+
public function addFile($name, array $coverageData, array $testData)
211207
{
212208
$file = new PHP_CodeCoverage_Report_Node_File(
213-
$name, $path, $this, $coverageData, $testData
209+
$name, $this, $coverageData, $testData
214210
);
215211

216212
$this->children[] = $file;

PHP/CodeCoverage/Report/Node/File.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@
6161
*/
6262
class PHP_CodeCoverage_Report_Node_File extends PHP_CodeCoverage_Report_Node
6363
{
64-
/**
65-
* @var string
66-
*/
67-
protected $path;
68-
6964
/**
7065
* @var array
7166
*/
@@ -145,19 +140,18 @@ class PHP_CodeCoverage_Report_Node_File extends PHP_CodeCoverage_Report_Node
145140
* Constructor.
146141
*
147142
* @param string $name
148-
* @param string $path
149143
* @param PHP_CodeCoverage_Report_Node $parent
150144
* @param array $coverageData
151145
* @param array $testData
152146
*/
153-
public function __construct($name, $path, PHP_CodeCoverage_Report_Node $parent, array $coverageData, array $testData)
147+
public function __construct($name, PHP_CodeCoverage_Report_Node $parent, array $coverageData, array $testData)
154148
{
155-
parent::__construct($name, $path, $parent);
149+
parent::__construct($name, $parent);
156150

157151
$this->coverageData = $coverageData;
158152
$this->testData = $testData;
159153
$this->ignoredLines = PHP_CodeCoverage_Util::getLinesToBeIgnored(
160-
$path
154+
$this->getPath()
161155
);
162156

163157
$this->calculateStatistics();

PHP/CodeCoverage/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public static function reducePaths(&$files)
473473

474474
ksort($files);
475475

476-
return $commonPath;
476+
return substr($commonPath, 0, -1);
477477
}
478478

479479
/**

Tests/PHP/CodeCoverage/UtilTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function testReducePaths()
273273
$files
274274
);
275275

276-
$this->assertEquals('/home/sb/Money/', $commonPath);
276+
$this->assertEquals('/home/sb/Money', $commonPath);
277277
}
278278

279279
/**

0 commit comments

Comments
 (0)