Passed
Push — 10.x ( 7ef113...ba9d3e )
by Andrey
13:56
created

Add::filenames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Helldar\LaravelLangPublisher\Comparators;
6
7
use Helldar\LaravelLangPublisher\Facades\Helpers\Config;
8
use Helldar\LaravelLangPublisher\Facades\Support\Filter;
9
use Helldar\Support\Facades\Helpers\Arr;
10
use Helldar\Support\Facades\Helpers\Str;
11
12
class Add extends Base
13
{
14
    public function get(): array
15
    {
16
        foreach ($this->filenames() as $filename) {
17
            $user = $this->load($filename);
18
19
            $translated = $this->translations[$filename];
20
21
            $excludes = $this->excludes($filename, $user);
22
23
            $this->translations[$filename] = $this->merge($translated, $user, $excludes);
24
        }
25
26
        return $this->filter();
27
    }
28
29
    protected function filter(): array
30
    {
31
        return Filter::keys($this->keys)
32
            ->translated($this->translations)
33
            ->get();
34
    }
35
36
    protected function merge(array $translated, array $user, array $excludes): array
37
    {
38
        return $this->force
39
            ? Arr::merge($user, $translated, $excludes)
40
            : Arr::merge($translated, $user, $excludes);
41
    }
42
43
    protected function filenames(): array
44
    {
45
        return array_keys($this->keys);
46
    }
47
48
    protected function excludes(string $filename, array $user): array
49
    {
50
        foreach (Config::excludes() as $key => $values) {
51
            if (Str::contains($filename, $key)) {
52
                return Arr::only($user, $values);
53
            }
54
        }
55
56
        return [];
57
    }
58
}
59