Passed
Push — master ( 0c3b18...0300eb )
by Andrey
02:51 queued 11s
created

BaseCommand   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 92.59%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 11
eloc 21
c 3
b 0
f 0
dl 0
loc 58
ccs 25
cts 27
cp 0.9259
rs 10

8 Methods

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