Passed
Push — 10.x ( bec96d...3163fd )
by Andrey
12:10
created

Base::plugins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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\Console;
21
22
use Helldar\Contracts\LangPublisher\Processor;
23
use Helldar\LaravelLangPublisher\Facades\Helpers\Config;
24
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales;
25
use Illuminate\Console\Command;
26
27
abstract class Base extends Command
28
{
29
    protected $load = true;
30
31
    protected $processor;
32
33
    public function handle()
34
    {
35
        $this->collecting();
36
        $this->store();
37
    }
38
39
    protected function collecting(): void
40
    {
41
        foreach ($this->plugins() as $provider) {
42
            $this->info('Collecting ' . get_class($provider));
43
44
            $this->getProcessor()->provider($provider);
45
        }
46
    }
47
48
    protected function store(): void
49
    {
50
        $this->info('Storing...');
51
52
        $this->getProcessor()->store();
53
    }
54
55
    /**
56
     * @return \Helldar\Contracts\LangPublisher\Provider[]
57
     */
58
    protected function plugins(): array
59
    {
60
        return Config::plugins();
61
    }
62
63
    protected function getProcessor(): Processor
64
    {
65
        if (! empty($this->processor)) {
66
            return $this->processor;
67
        }
68
69
        /** @var Processor $processor */
70
        $processor = new $this->processor;
71
72
        return $this->processor = $processor
73
            ->locales($this->targetLocales())
74
            ->hasForce($this->hasForce())
75
            ->hasLoad($this->load);
76
    }
77
78
    protected function targetLocales(): array
79
    {
80
        return Locales::installed();
81
    }
82
83
    protected function hasForce(): bool
84
    {
85
        return $this->boolOption('force');
86
    }
87
88
    protected function hasFull(): bool
89
    {
90
        return $this->boolOption('force');
91
    }
92
93
    protected function boolOption(string $key): bool
94
    {
95
        return $this->hasOption($key) && $this->option($key);
96
    }
97
}
98