PathFinder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
c 3
b 0
f 0
dl 0
loc 32
ccs 7
cts 8
cp 0.875
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matchingPattern() 0 13 4
A ensureGlobBraceIsDefined() 0 4 2
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