Passed
Push — main ( 545ade...3cfdef )
by Andrey
79:39 queued 77:29
created

Missing   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 49
ccs 21
cts 21
cp 1
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A packageable() 0 10 1
A path() 0 3 1
A unnecessary() 0 3 1
A missing() 0 3 1
A locales() 0 5 1
A available() 0 3 1
A defaultLocale() 0 3 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Services;
4
5
use Helldar\LaravelLangPublisher\Concerns\Pathable;
6
use Helldar\LaravelLangPublisher\Constants\Locales as LocalesList;
7
use Helldar\LaravelLangPublisher\Facades\ArrayProcessor;
8
use Helldar\LaravelLangPublisher\Facades\Locales;
9
use Helldar\Support\Concerns\Makeable;
10
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
11
12
final class Missing
13
{
14
    use Makeable;
15
    use Pathable;
16
17
    protected $locale = LocalesList::ENGLISH;
18
19 1
    public function missing(string $package): array
20
    {
21 1
        return array_diff($this->packageable($package), $this->available());
22
    }
23
24 1
    public function unnecessary(string $package): array
25
    {
26 1
        return array_diff($this->available(), $this->packageable($package));
27
    }
28
29 2
    protected function available(): array
30
    {
31 2
        return Locales::available(true);
32
    }
33
34 2
    protected function packageable(string $package): array
35
    {
36 2
        $items = $this->locales($package);
37
38 2
        return ArrayProcessor::of($items)
39 2
            ->push($this->defaultLocale())
40 2
            ->unique()
41 2
            ->sort()
42 2
            ->values()
43 2
            ->toArray();
44
    }
45
46 2
    protected function defaultLocale(): string
47
    {
48 2
        return LocalesList::ENGLISH;
49
    }
50
51 2
    protected function locales(string $package): array
52
    {
53 2
        $path = $this->path($package);
54
55 2
        return Directory::names($path);
56
    }
57
58 2
    protected function path(string $package): string
59
    {
60 2
        return $this->pathLocales($package);
61
    }
62
}
63