Passed
Push — 9.x ( c610c7...55b0ab )
by Andrey
11:17
created

Packages::all()   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 0
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\Config as ConfigFacade;
8
use Helldar\Support\Facades\Helpers\Arr as ArrHelper;
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
        $unique   = $this->unique($packages);
19
        $filtered = $this->filter($unique);
20
        $sorted   = $this->sort($filtered);
21
22
        return $this->values($sorted);
23
    }
24
25
    public function all(): array
26
    {
27
        return ConfigFacade::packages();
28
    }
29
30
    protected function filter(array $packages): array
31
    {
32
        return array_filter($packages, static function ($package) {
33
            $source = $this->pathSource($package, LocalesList::ENGLISH);
34
            $target = $this->pathSource($package, LocalesList::RUSSIAN);
35
36
            return Directory::exists($source) && Directory::exists($target);
37
        });
38
    }
39
40
    protected function unique(array $packages): array
41
    {
42
        return array_unique($packages);
43
    }
44
45
    protected function values(array $packages): array
46
    {
47
        return array_values($packages);
48
    }
49
50
    protected function sort(array $packages): array
51
    {
52
        return ArrHelper::sort($packages);
53
    }
54
}
55