Skip to content

Commit 7184606

Browse files
committed
AbstractGenerator::getCommonFilesPath() replaced by Helpers::findCommonDirectory()
1 parent 2cbf029 commit 7184606

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/CodeCoverage/Generators/AbstractGenerator.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace Tester\CodeCoverage\Generators;
1111

12+
use Tester\Helpers;
13+
1214

1315
/**
1416
* Code coverage report generator.
@@ -56,7 +58,7 @@ public function __construct(string $file, array $sources = [])
5658
}, ARRAY_FILTER_USE_KEY);
5759

5860
if (!$sources) {
59-
$sources = [self::getCommonFilesPath(array_keys($this->data))];
61+
$sources = [Helpers::findCommonDirectory(array_keys($this->data))];
6062

6163
} else {
6264
foreach ($sources as $source) {
@@ -118,19 +120,10 @@ protected function getSourceIterator(): \Iterator
118120
}
119121

120122

123+
/** @deprecated */
121124
protected static function getCommonFilesPath(array $files): string
122125
{
123-
$path = reset($files);
124-
for ($i = 0; $i < strlen($path); $i++) {
125-
foreach ($files as $file) {
126-
if (!isset($file[$i]) || $path[$i] !== $file[$i]) {
127-
$path = substr($path, 0, $i);
128-
break 2;
129-
}
130-
}
131-
}
132-
133-
return rtrim(is_dir($path) ? $path : dirname($path), DIRECTORY_SEPARATOR);
126+
return Helpers::findCommonDirectory($files);
134127
}
135128

136129

src/CodeCoverage/Generators/HtmlGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace Tester\CodeCoverage\Generators;
1111

12+
use Tester\Helpers;
13+
1214

1315
/**
1416
* Code coverage report generator.
@@ -70,7 +72,7 @@ private function parse(): void
7072
}
7173

7274
$this->files = [];
73-
$commonSourcesPath = self::getCommonFilesPath($this->sources) . DIRECTORY_SEPARATOR;
75+
$commonSourcesPath = Helpers::findCommonDirectory($this->sources) . DIRECTORY_SEPARATOR;
7476
foreach ($this->getSourceIterator() as $entry) {
7577
$entry = (string) $entry;
7678

0 commit comments

Comments
 (0)