Skip to content
This repository was archived by the owner on Aug 28, 2020. It is now read-only.

Commit 21d53a4

Browse files
committed
optimized path compare utility
1 parent 9720efb commit 21d53a4

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

Classes/Utility/PathUtility.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@ public static function path2array($path, $delimiter = '/')
3030
public static function compare($pathOne, $pathTwo, $delimiter = '/')
3131
{
3232
$pathOne = self::path2array($pathOne);
33-
$pathTwo = self::path2array($pathTwo);
3433

3534
for ($distance = 0; $distance < count($pathOne); $distance++) {
36-
for ($p2index = 0; $p2index < count($pathTwo); $p2index++) {
37-
if ($pathOne[$distance] === $pathTwo[$p2index]) {
38-
return $distance + $p2index;
39-
}
35+
if ($pathOne[$distance] === $pathTwo) {
36+
return $distance;
4037
}
4138
}
4239

43-
return -1;
40+
return null;
4441
}
4542
}

0 commit comments

Comments
 (0)