Total Complexity | 5 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class FilesPathService |
||
8 | { |
||
9 | /** |
||
10 | * @param string[] $patterns |
||
11 | * @return string[] |
||
12 | */ |
||
13 | public static function getPathToFiles(array $patterns): array |
||
14 | { |
||
15 | $pathToFiles = [[]]; |
||
16 | foreach ($patterns as $pattern) { |
||
17 | if (is_file($pattern)) { |
||
18 | $pathToFiles[] = [$pattern]; |
||
19 | } else { |
||
20 | $pathToFiles[] = self::globRecursive($pattern); |
||
21 | } |
||
22 | } |
||
23 | |||
24 | $pathToFiles = array_merge(...$pathToFiles); |
||
25 | $pathToFiles = str_replace('\\', '/', $pathToFiles); |
||
26 | |||
27 | return array_unique($pathToFiles); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @param string $pattern |
||
32 | * @return string[] |
||
33 | * |
||
34 | * @link https://www.php.net/manual/en/function.glob.php#106595 |
||
35 | */ |
||
36 | private static function globRecursive(string $pattern): array |
||
46 | } |
||
47 | } |
||
48 |