Wildcard   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 16
c 1
b 0
f 0
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A matches() 0 18 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