Passed
Push — 9.x ( 55b0ab...1730b8 )
by Andrey
14:27
created

Packages::sort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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