PathFinder::matchingPattern()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
c 3
b 0
f 0
dl 0
loc 13
ccs 3
cts 3
cp 1
rs 10
cc 4
nc 3
nop 1
crap 4
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