Wildcard::matches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 9.8666
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace hamburgscleanest\GuzzleAdvancedThrottle;
4
5
use Illuminate\Support\Arr;
6
7
class Wildcard
8
{
9
    private const REGEX_WILDCARD = '/{[^}]*}/';
10
    private const REGEX_ANY_CHAR = '(.*)';
11
    private const REGEX_DELIMITER = '/';
12
13 7
    public static function matches(string $wildcardText, string $text): bool
14
    {
15 7
        $regex = \preg_replace(self::REGEX_WILDCARD, self::REGEX_ANY_CHAR, $wildcardText);
16
17 7
        $matches = [];
18 7
        \preg_match_all(
19 7
            self::REGEX_DELIMITER . \str_replace(
20 7
                self::REGEX_DELIMITER,
21 7
                '\\' . self::REGEX_DELIMITER,
22
                $regex
23 7
            ) . self::REGEX_DELIMITER,
24
            $text,
25
            $matches
26
        );
27
28 7
        \array_shift($matches);
29
30 7
        return \strtr($text, \array_fill_keys(Arr::flatten($matches), self::REGEX_ANY_CHAR)) === $regex;
31
    }
32
}
33