Skip to content

Commit

Permalink
Reduced complexity of CollectionPersister::excludeSubPaths method.
Browse files Browse the repository at this point in the history
  • Loading branch information
watari committed Oct 26, 2018
1 parent 8343cd5 commit 98fc6af
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
use function array_keys;
use function array_map;
use function array_reverse;
use function array_unique;
use function array_values;
use function count;
use function end;
use function get_class;
use function implode;
use function sort;
use function spl_object_hash;
use function sprintf;
use function strpos;
Expand Down Expand Up @@ -629,25 +630,19 @@ private function executeQuery(object $document, array $newObj, array $options) :
*/
private function excludeSubPaths(array $paths) : array
{
$checkedPaths = [];
$pathsAmount = count($paths);
$paths = array_unique($paths);
for ($i = 0; $i < $pathsAmount; $i++) {
$isSubPath = false;
$j = 0;
for (; $j < $pathsAmount; $j++) {
if ($i !== $j && strpos($paths[$i], $paths[$j]) === 0) {
$isSubPath = true;
break;
}
}
if ($isSubPath) {
if (empty($paths)) {
return $paths;
}
sort($paths);
$uniquePaths = [$paths[0]];
for ($i = 1; $i < count($paths); ++$i) {
if (strpos($paths[$i], end($uniquePaths)) === 0) {
continue;
}

$checkedPaths[] = $paths[$i];
$uniquePaths[] = $paths[$i];
}

return $checkedPaths;
return $uniquePaths;
}
}

0 comments on commit 98fc6af

Please sign in to comment.