Passed
Branch master (e09f8d)
by Peter
26:53
created

YamlFilesPathService::globRecursive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace YamlStandards\Command\Service;
6
7
class YamlFilesPathService
8
{
9
    /**
10
     * @param string[] $patterns
11
     * @return string[]
12
     */
13 13
    public static function getPathToYamlFiles(array $patterns): array
14
    {
15 13
        $pathToFiles = [[]];
16 13
        foreach ($patterns as $pattern) {
17 13
            $pathToFiles[] = self::globRecursive($pattern);
18
        }
19
20 13
        $pathToFiles = array_merge(...$pathToFiles);
21 13
        $pathToFiles = str_replace('\\', '/', $pathToFiles);
22
23 13
        return array_unique($pathToFiles);
24
    }
25
26
    /**
27
     * @param string $pattern
28
     * @return string[]
29
     *
30
     * @link https://www.php.net/manual/en/function.glob.php#106595
31
     */
32 13
    private static function globRecursive(string $pattern): array
33
    {
34 13
        $files = glob($pattern);
35
36 13
        foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
37 9
            $files = array_merge($files, self::globRecursive($dir . '/' . basename($pattern)));
0 ignored issues
show
Bug introduced by
It seems like $files can also be of type false; however, parameter $array1 of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            $files = array_merge(/** @scrutinizer ignore-type */ $files, self::globRecursive($dir . '/' . basename($pattern)));
Loading history...
38
        }
39
40 13
        return $files;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $files could return the type false which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
41
    }
42
}
43