Passed
Pull Request — main (#123)
by Andrey
42:12 queued 26:54
created

Remove::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 10
c 1
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\Processors;
21
22
use Helldar\Contracts\LangPublisher\Provider;
23
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales;
24
use Helldar\LaravelLangPublisher\Facades\Support\Filesystem;
25
26
class Remove extends BaseProcessor
27
{
28
    protected $paths = [];
29
30
    public function handle(Provider $provider): void
31
    {
32
        foreach ($this->locales as $locale) {
33
            $json = $this->resourcesPath($locale . '.json');
34
            $php  = $this->resourcesPath($locale);
35
36
            $this->push($json, $php);
37
        }
38
    }
39
40
    public function finish(): void
41
    {
42
        Filesystem::delete($this->paths);
43
    }
44
45
    protected function prepareLocales(array $locales): array
46
    {
47
        $except = Locales::protects();
48
49
        return array_diff($locales, $except);
50
    }
51
52
    protected function push(string ...$paths): void
53
    {
54
        foreach ($paths as $path) {
55
            array_push($this->paths, $path);
56
        }
57
    }
58
}
59