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

Packages   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A unique() 0 3 1
A sort() 0 3 1
A filter() 0 7 2
A values() 0 3 1
A filtered() 0 8 1
A all() 0 3 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\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