Passed
Push — 10.x ( 592eb6...b6c4ed )
by Andrey
18:51 queued 03:57
created

Base::finish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
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\Console;
21
22
use Helldar\LaravelLangPublisher\Concerns\Ask;
23
use Helldar\LaravelLangPublisher\Concerns\Paths;
24
use Helldar\LaravelLangPublisher\Facades\Helpers\Config;
25
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales;
26
use Illuminate\Console\Command;
27
28
abstract class Base extends Command
29
{
30
    use Ask;
31
    use Paths;
32
33
    /** @var \Helldar\Contracts\LangPublisher\Processor */
34
    protected $processor;
35
36
    public function handle()
37
    {
38
        $this->resolveProcessor();
39
40
        $this->collecting();
41
42
        $this->finish();
43
    }
44
45
    protected function finish(): void
46
    {
47
        $this->info('Saving changes...');
48
49
        $this->processor->finish();
50
    }
51
52
    protected function resolveProcessor(): void
53
    {
54
        $locales = $this->targetLocales();
55
        $full    = $this->hasFull();
56
57
        $this->processor = new $this->processor($locales, $full);
58
    }
59
60
    protected function collecting(): void
61
    {
62
        foreach ($this->plugins() as $provider) {
63
            $this->info('Processing ' . get_class($provider) . '...');
64
65
            $this->processor->handle($provider);
66
        }
67
    }
68
69
    /**
70
     * @return \Helldar\Contracts\LangPublisher\Provider[]
71
     */
72
    protected function plugins(): array
73
    {
74
        return Config::plugins();
75
    }
76
77
    protected function targetLocales(): array
78
    {
79
        return Locales::installed();
80
    }
81
82
    protected function getAllLocales(): array
83
    {
84
        return Locales::installed();
85
    }
86
87
    protected function hasFull(): bool
88
    {
89
        return $this->hasOption('full')
90
            && $this->option('full');
91
    }
92
}
93