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

BaseProcessor::setResource()   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 3
dl 0
loc 3
rs 10
c 0
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\Processors;
21
22
use Helldar\Contracts\LangPublisher\Processor;
23
use Helldar\Contracts\LangPublisher\Provider;
24
use Helldar\LaravelLangPublisher\Concerns\Has;
25
use Helldar\LaravelLangPublisher\Concerns\Keyable;
26
use Helldar\LaravelLangPublisher\Concerns\Paths;
27
use Helldar\LaravelLangPublisher\Resources\Translation;
28
29
abstract class BaseProcessor implements Processor
30
{
31
    use Has;
32
    use Keyable;
33
    use Paths;
34
35
    /** @var Provider */
36
    protected $provider;
37
38
    /** @var array */
39
    protected $locales = [];
40
41
    /** @var \Helldar\LaravelLangPublisher\Resources\Translation */
42
    protected $resources;
43
44
    /** @var \Helldar\Contracts\LangPublisher\Comparator */
45
    protected $comparator;
46
47
    /** @var bool */
48
    protected $full;
49
50
    public function __construct(array $locales, bool $full)
51
    {
52
        $this->locales = $this->prepareLocales($locales);
53
54
        $this->resources = Translation::make();
55
56
        $this->full = $full;
57
    }
58
59
    protected function compare(): array
60
    {
61
        $keys  = $this->resources->getKeys();
62
        $trans = $this->resources->getTranslations();
63
64
        return (new $this->comparator($keys, $trans, $this->full))->get();
65
    }
66
67
    protected function prepareLocales(array $locales): array
68
    {
69
        return $locales;
70
    }
71
72
    protected function setResourceKeys(string $target, array $keys): void
73
    {
74
        $this->resources->keys($target, $keys);
75
    }
76
77
    protected function setResource(string $locale, string $target, array $translations): void
78
    {
79
        $this->resources->translation($locale, $target, $translations);
80
    }
81
}
82