Passed
Push — 10.x ( a3a026...912076 )
by Andrey
11:38
created

Base::getProcessor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Base::plugins() 0 3 1
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\Optionable;
23
use Helldar\LaravelLangPublisher\Concerns\Paths;
24
use Helldar\LaravelLangPublisher\Facades\Helpers\Config;
25
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales;
26
use Helldar\LaravelLangPublisher\Facades\Support\Filesystem;
27
use Helldar\LaravelLangPublisher\Facades\Support\Filter;
28
use Illuminate\Console\Command;
29
30
abstract class Base extends Command
31
{
32
    use Optionable;
33
    use Paths;
34
35
    protected $processor;
36
37
    public function handle()
38
    {
39
        $this->resolveProcessor();
40
41
        $this->collecting();
42
43
        $this->store($this->filter());
44
    }
45
46
    protected function resolveProcessor(): void
47
    {
48
        $locales = $this->targetLocales();
49
        $force   = $this->hasForce();
50
51
        $this->processor = new $this->processor($locales, $force);
52
    }
53
54
    protected function collecting(): void
55
    {
56
        foreach ($this->plugins() as $provider) {
57
            $this->info('Collecting ' . get_class($provider) . '...');
58
59
            $this->processor->provider($provider);
60
        }
61
    }
62
63
    protected function filter(): array
64
    {
65
        $this->info('Filtering...');
66
67
        $source     = $this->processor->source();
68
        $translated = $this->processor->translated();
69
70
        return Filter::keys($source)
71
            ->translated($translated)
72
            ->get();
73
    }
74
75
    protected function store(array $items): void
76
    {
77
        $this->info('Storing...');
78
79
        foreach ($items as $filename => $values) {
80
            $path = $this->resourcesPath($filename);
81
82
            Filesystem::store($path, $values);
83
        }
84
    }
85
86
    /**
87
     * @return \Helldar\Contracts\LangPublisher\Provider[]
88
     */
89
    protected function plugins(): array
90
    {
91
        return Config::plugins();
92
    }
93
94
    protected function targetLocales(): array
95
    {
96
        return Locales::installed();
97
    }
98
}
99