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

BaseCommand   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
eloc 22
c 3
b 0
f 0
dl 0
loc 58
ccs 24
cts 26
cp 0.9231
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setProcessor() 0 3 2
A wantsJson() 0 3 1
A exec() 0 8 2
A getLocales() 0 5 2
A locales() 0 3 1
A __construct() 0 7 1
A isForce() 0 3 1
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