Passed
Pull Request — main (#123)
by Andrey
42:12 queued 26:54
created

Translation::getKeys()   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 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the "andrey-helldar/laravel-lang-publisher" project.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @author Andrey Helldar <[email protected]>
10
 *
11
 * @copyright 2021 Andrey Helldar
12
 *
13
 * @license MIT
14
 *
15
 * @see https://github.com/andrey-helldar/laravel-lang-publisher
16
 */
17
18
declare(strict_types=1);
19
20
namespace Helldar\LaravelLangPublisher\Resources;
21
22
use Helldar\Contracts\LangPublisher\Translation as Resource;
23
use Helldar\Support\Concerns\Makeable;
24
use Helldar\Support\Facades\Helpers\Arr;
25
26
class Translation implements Resource
27
{
28
    use Makeable;
29
30
    protected $keys = [];
31
32
    protected $translations = [];
33
34
    public function getKeys(): array
35
    {
36
        return $this->keys;
37
    }
38
39
    public function keys(string $target, array $keys): Resource
40
    {
41
        $values = $this->keys[$target] ?? [];
42
43
        $this->keys[$target] = $this->merge($values, $keys);
44
45
        return $this;
46
    }
47
48
    public function translation(string $locale, string $target, array $translations): Resource
49
    {
50
        $values = $this->translations[$target][$locale] ?? [];
51
52
        $this->translations[$target][$locale] = $this->merge($values, $translations);
53
54
        return $this;
55
    }
56
57
    public function getTranslations(): array
58
    {
59
        return $this->translations;
60
    }
61
62
    protected function merge(array ...$arrays): array
63
    {
64
        return Arr::merge(...$arrays);
65
    }
66
}
67