Skip to content

Commit

Permalink
Merge pull request #93 from andrey-helldar/9.x
Browse files Browse the repository at this point in the history
Fixed work with excluded translations
  • Loading branch information
Andrey Helldar committed Apr 14, 2021
2 parents 3780228 + 28b7415 commit 577003c
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/Services/Comparators/Comparator.php
Expand Up @@ -79,7 +79,6 @@ protected function splitNotSortable(): void
$this->log('Splitting main arrays into excludes...');

if (! empty($this->excludes)) {
$this->prepareExcludes();
$this->ranExcludes();
$this->extractExcludes();
}
Expand All @@ -98,9 +97,7 @@ protected function ranExcludes(): void
{
$this->log('Retrieving values from arrays...');

foreach ($this->excludes as $key => &$value) {
$value = $this->getFallbackValue($this->source, $this->target, $key);
}
$this->excludes = $this->getExcludedValues($this->source, $this->target, $this->excludes);
}

protected function extractExcludes(): void
Expand All @@ -113,11 +110,14 @@ protected function extractExcludes(): void
$this->target = Arr::except($this->target, $keys);
}

protected function getFallbackValue(array $source, array $target, string $key): array
protected function getExcludedValues(array $source, array $target, array $keys): array
{
$this->log('Retrieving values from arrays by the "' . $key . '" key...');
$this->log('Retrieving values from arrays by the "' . implode('", "', $keys) . '" key...');

$excluded_source = Arr::only($source, $keys);
$excluded_target = Arr::only($target, $keys);

return Arr::get($target, $key) ?: Arr::get($source, $key, []);
return array_merge($excluded_target, $excluded_source);
}

protected function sort(array $array): array
Expand All @@ -126,11 +126,4 @@ protected function sort(array $array): array

return Arr::ksort($array);
}

protected function prepareExcludes(): void
{
$this->log('Exchanges all keys with their associated values in an array...');

$this->excludes = array_flip($this->excludes);
}
}

0 comments on commit 577003c

Please sign in to comment.