Passed
Push — main ( 27f19e...cbb4d9 )
by Andrey
14:59 queued 12:22
created

Files::filesLength()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 5
nop 0
dl 0
loc 23
ccs 12
cts 12
cp 1
crap 5
rs 9.6111
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Concerns;
4
5
use Helldar\LaravelLangPublisher\Constants\Locales as LocalesList;
6
use Helldar\Support\Facades\Helpers\Arr;
7
use Helldar\Support\Facades\Helpers\Filesystem\File;
8
use Helldar\Support\Facades\Helpers\Str;
9
10
trait Files
11
{
12
    protected $files_length = 0;
13
14
    protected $files;
15
16 16
    protected function files(string $package, string $locale = LocalesList::ENGLISH): array
17
    {
18 16
        $this->log('Getting a list of files for the ', $package, 'package...');
0 ignored issues
show
Bug introduced by
It seems like log() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $this->/** @scrutinizer ignore-call */ 
19
               log('Getting a list of files for the ', $package, 'package...');
Loading history...
19
20 16
        if ($this->files[$package] ?? false) {
21 15
            return $this->files[$package];
22
        }
23
24 16
        $path = $this->pathSource($package, $locale);
0 ignored issues
show
Bug introduced by
It seems like pathSource() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        /** @scrutinizer ignore-call */ 
25
        $path = $this->pathSource($package, $locale);
Loading history...
25
26 16
        return $this->files[$package] = File::names($path, static function ($filename) {
27 16
            return ! Str::contains($filename, 'inline');
28 16
        });
29
    }
30
31 16
    protected function filesLength(): int
32
    {
33 16
        $this->log('Getting the maximum length of a filenames...');
34
35 16
        if ($this->files_length > 0) {
36 16
            return $this->files_length;
37
        }
38
39 16
        $this->log('Calculating the maximum length of a filenames...');
40
41 16
        $files = [];
42
43 16
        foreach ($this->packages() as $package) {
0 ignored issues
show
Bug introduced by
It seems like packages() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        foreach ($this->/** @scrutinizer ignore-call */ packages() as $package) {
Loading history...
44 16
            $files = array_merge($files, $this->files($package));
45
46 16
            foreach ($this->plugins() as $plugin) {
0 ignored issues
show
Bug introduced by
It seems like plugins() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            foreach ($this->/** @scrutinizer ignore-call */ plugins() as $plugin) {
Loading history...
47 16
                if ($plugin->has()) {
48 16
                    $files = array_merge($files, $plugin->source());
49
                }
50
            }
51
        }
52
53 16
        return $this->files_length = Arr::longestStringLength(array_unique($files));
54
    }
55
}
56