From eaaeb7b230eed50383cefa8e98bde5d810a9005c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Wed, 20 Feb 2019 13:39:28 +0000 Subject: [PATCH] AbstractGenerator::getCommonFilesPath() replaced by Helpers::findCommonDirectory() --- .../Generators/AbstractGenerator.php | 17 +++++------------ src/CodeCoverage/Generators/HtmlGenerator.php | 4 +++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/CodeCoverage/Generators/AbstractGenerator.php b/src/CodeCoverage/Generators/AbstractGenerator.php index 68f09939..1fab0663 100644 --- a/src/CodeCoverage/Generators/AbstractGenerator.php +++ b/src/CodeCoverage/Generators/AbstractGenerator.php @@ -9,6 +9,8 @@ namespace Tester\CodeCoverage\Generators; +use Tester\Helpers; + /** * Code coverage report generator. @@ -56,7 +58,7 @@ public function __construct(string $file, array $sources = []) }, ARRAY_FILTER_USE_KEY); if (!$sources) { - $sources = [self::getCommonFilesPath(array_keys($this->data))]; + $sources = [Helpers::findCommonDirectory(array_keys($this->data))]; } else { foreach ($sources as $source) { @@ -118,19 +120,10 @@ protected function getSourceIterator(): \Iterator } + /** @deprecated */ protected static function getCommonFilesPath(array $files): string { - $path = reset($files); - for ($i = 0; $i < strlen($path); $i++) { - foreach ($files as $file) { - if (!isset($file[$i]) || $path[$i] !== $file[$i]) { - $path = substr($path, 0, $i); - break 2; - } - } - } - - return rtrim(is_dir($path) ? $path : dirname($path), DIRECTORY_SEPARATOR); + return Helpers::findCommonDirectory($files); } diff --git a/src/CodeCoverage/Generators/HtmlGenerator.php b/src/CodeCoverage/Generators/HtmlGenerator.php index 68e59d47..e9117efd 100644 --- a/src/CodeCoverage/Generators/HtmlGenerator.php +++ b/src/CodeCoverage/Generators/HtmlGenerator.php @@ -9,6 +9,8 @@ namespace Tester\CodeCoverage\Generators; +use Tester\Helpers; + /** * Code coverage report generator. @@ -70,7 +72,7 @@ private function parse(): void } $this->files = []; - $commonSourcesPath = self::getCommonFilesPath($this->sources) . DIRECTORY_SEPARATOR; + $commonSourcesPath = Helpers::findCommonDirectory($this->sources) . DIRECTORY_SEPARATOR; foreach ($this->getSourceIterator() as $entry) { $entry = (string) $entry;