PathFinder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 2
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matchingPattern() 0 14 4
A ensureGlobBraceIsDefined() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Config;
6
7
use Override;
8
9
use function define;
10
use function defined;
11
12
final class PathFinder implements PathFinderInterface
13
{
14
    /** @var array<string,array<int,string>> */
15
    private static array $cache = [];
16
17
    /**
18
     * @return string[]
19
     */
20
    #[Override]
21
    public function matchingPattern(string $pattern): array
22
    {
23
        if ($pattern === '') {
24
            return [];
25
        }
26
27
        if (isset(self::$cache[$pattern])) {
28
            return self::$cache[$pattern];
29
        }
30
31
        $this->ensureGlobBraceIsDefined();
32
33
        return self::$cache[$pattern] = glob($pattern, GLOB_BRACE) ?: [];
34
    }
35
36
    /**
37
     * Note: The GLOB_BRACE flag is not available on some non-GNU systems, like Solaris or Alpine Linux.
38
     *
39
     * @see https://www.php.net/manual/en/function.glob.php
40
     */
41
    private function ensureGlobBraceIsDefined(): void
42
    {
43
        if (!defined('GLOB_BRACE')) {
44
            define('GLOB_BRACE', 0x10);
45
        }
46
    }
47
}
48