Skip to content

Commit

Permalink
Fix the result when comparing directories where the parent comes befo…
Browse files Browse the repository at this point in the history
…re the child
  • Loading branch information
martin-rueegg committed Sep 18, 2023
1 parent af2f9e6 commit e921138
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/PathComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public function __construct(array $directories) {
}

public function getCommonBase() {
if (count($this->directories) == 0) {
if (count($this->directories) === 0) {
return '/';
}
$result = $this->directories[0];
foreach($this->directories as $dir) {
$result = substr($dir, 0, $this->commonPrefix($result, $dir));
$result = substr($dir, 0, $this->commonPrefix($result, $dir)).'/';
}
return ($result ?: '/');
return (rtrim($result, '/') ?: '/');
}


Expand Down
3 changes: 3 additions & 0 deletions tests/PathComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function directoriesProvider() {
'two' => array(
array(__DIR__, dirname(__DIR__)), dirname(__DIR__)
),
'shortfirst' => array(
array(dirname(__DIR__), __DIR__), dirname(__DIR__)
),
'parents' => array(
array(__DIR__ . '/../src', __DIR__ . '/../tests/_data'), dirname(__DIR__)
),
Expand Down

0 comments on commit e921138

Please sign in to comment.