PathFinder::ensureGlobBraceIsDefined()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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