Passed
Push — main ( 156ba4...e2c36a )
by Andrey
11:42 queued 13s
created

Missing::unnecessary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Support;
4
5
use DirectoryIterator;
6
use Helldar\LaravelLangPublisher\Facades\File as FileFacade;
7
use Helldar\LaravelLangPublisher\Facades\Locale as LocaleSupport;
8
use Illuminate\Support\Facades\Config as IlluminateConfig;
9
10
class Missing
11
{
12 2
    public function missing(): array
13
    {
14 2
        return array_diff($this->sourceAvailable(), $this->mainAvailable());
15
    }
16
17 2
    public function unnecessary(): array
18
    {
19 2
        return array_diff($this->mainAvailable(), $this->sourceAvailable());
20
    }
21
22 2
    protected function mainAvailable(): array
23
    {
24 2
        return LocaleSupport::availableAll();
25
    }
26 2
27 2
    protected function sourceAvailable(): array
28 2
    {
29
        $names = ['en'];
30
31
        foreach ($this->directories() as $file) {
32 2
            if (! $file->isDot() && $file->isDir()) {
33
                $names[] = $file->getFilename();
34
            }
35 2
        }
36
37 2
        return array_values(array_unique($names));
38
    }
39 2
40
    protected function sourcePath(): string
41
    {
42
        $path = IlluminateConfig::get(Config::KEY_PRIVATE . '.vendor');
43
44
        return rtrim($path, '/') . '/src';
45 2
    }
46
47 2
    /**
48
     * @return \DirectoryIterator|\DirectoryIterator[]
49
     */
50
    protected function directories(): DirectoryIterator
51
    {
52
        return FileFacade::files($this->sourcePath());
53
    }
54
}
55