Passed
Push — 10.x ( 52de98...21fac1 )
by Andrey
14:55
created

Translation::merge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Helldar\LaravelLangPublisher\Resources;
6
7
use Helldar\Contracts\LangPublisher\Translation as Resource;
8
use Helldar\Support\Concerns\Makeable;
9
use Helldar\Support\Facades\Helpers\Arr;
10
11
class Translation implements Resource
12
{
13
    use Makeable;
14
15
    protected $keys = [];
16
17
    protected $translations = [];
18
19
    public function getKeys(): array
20
    {
21
        return $this->keys;
22
    }
23
24
    public function keys(string $target, array $keys): Resource
25
    {
26
        $values = $this->keys[$target] ?? [];
27
28
        $this->keys[$target] = $this->merge($values, $keys);
29
30
        return $this;
31
    }
32
33
    public function translation(string $locale, string $target, array $translations): Resource
34
    {
35
        $values = $this->translations[$target][$locale] ?? [];
36
37
        $this->translations[$target][$locale] = $this->merge($values, $translations);
38
39
        return $this;
40
    }
41
42
    public function getTranslations(): array
43
    {
44
        return $this->translations;
45
    }
46
47
    protected function merge(array ...$arrays): array
48
    {
49
        return Arr::merge(...$arrays);
50
    }
51
}
52