Passed
Pull Request — main (#96)
by Andrey
50:33 queued 35:34
created

Packages   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 7 2
A filtered() 0 5 1
A map() 0 8 1
A all() 0 5 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use Helldar\LaravelLangPublisher\Concerns\Pathable;
6
use Helldar\LaravelLangPublisher\Constants\Locales as LocalesList;
7
use Helldar\LaravelLangPublisher\Facades\ArrayProcessor as ArrProcessor;
8
use Helldar\LaravelLangPublisher\Facades\Config as ConfigFacade;
9
use Helldar\Support\Facades\Helpers\Filesystem\Directory;
10
11
final class Packages
12
{
13
    use Pathable;
14
15
    public function filtered(): array
16
    {
17
        $packages = $this->all();
18
19
        return $this->map($packages);
20
    }
21
22
    public function all(): array
23
    {
24
        $packages = ConfigFacade::packages();
25
26
        return ArrProcessor::of($packages)->sort()->toArray();
27
    }
28
29
    protected function filter(): callable
30
    {
31
        return function ($package) {
32
            $source = $this->pathSource($package, LocalesList::ENGLISH);
33
            $target = $this->pathSource($package, LocalesList::RUSSIAN);
34
35
            return Directory::exists($source) && Directory::exists($target);
36
        };
37
    }
38
39
    protected function map(array $packages): array
40
    {
41
        return ArrProcessor::of($packages)
42
            ->unique()
43
            ->filter($this->filter())
44
            ->values()
45
            ->sort()
46
            ->toArray();
47
    }
48
}
49