Passed
Push — master ( 68f9e3...36b0af )
by Andrey
02:57 queued 39s
created

BaseCommand::exec()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Console;
4
5
use Helldar\LaravelLangPublisher\Services\Localization;
6
use Helldar\LaravelLangPublisher\Support\Result;
7
use Helldar\LaravelLangPublisher\Traits\Containable;
8
use Helldar\LaravelLangPublisher\Traits\Containers\Pathable;
9
use Helldar\LaravelLangPublisher\Traits\Containers\Processable;
10
use Illuminate\Console\Command;
11
12
abstract class BaseCommand extends Command
13
{
14
    use Containable;
15
    use Processable;
16
    use Pathable;
17
18
    /** @var \Helldar\LaravelLangPublisher\Services\Localization */
19
    protected $localization;
20
21
    /** @var \Helldar\LaravelLangPublisher\Support\Result */
22
    protected $result;
23
24 36
    public function __construct(Localization $localization, Result $result)
25
    {
26 36
        parent::__construct();
27
28 36
        $this->localization = $localization;
29
30 36
        $this->result = $result->setOutput($this);
31 36
    }
32
33 12
    protected function locales(): array
34
    {
35 12
        return (array) $this->argument('locales');
36
    }
37
38 12
    protected function isForce(): bool
39
    {
40 12
        return (bool) $this->option('force');
41
    }
42
43 12
    protected function wantsJson(): bool
44
    {
45 12
        return (bool) $this->option('json');
46
    }
47
48 12
    protected function setProcessor(string $php, string $json): void
49
    {
50 12
        $this->processor = $this->wantsJson() ? $json : $php;
51 12
    }
52
53 12
    protected function exec(array $locales): void
54
    {
55 12
        foreach ($this->getLocales($locales) as $locale) {
56 12
            $this->result->merge(
57 12
                $this->localization
58 12
                    ->setPath($this->getPath())
59 12
                    ->setProcessor($this->getProcessor())
60 12
                    ->run($locale, $this->isForce())
61
            );
62
        }
63
    }
64
65 12
    protected function getLocales(array $locales): array
66
    {
67 12
        return $this->locales() === ['*']
68
            ? $locales
69 12
            : $this->locales();
70
    }
71
}
72