Passed
Branch release/v2.0.0 (caca50)
by Anatoly
02:02
created

path_match()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 15
rs 9.6111
cc 5
nc 4
nop 3
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router;
13
14
/**
15
 * Import functions
16
 */
17
use function is_int;
18
use function preg_match;
19
20
/**
21
 * Compares the given path and the given subject...
22
 *
23
 * @param string $path
24
 * @param string $subject
25
 *
26
 * @return bool
27
 */
28
function path_match(string $path, string $subject, &$attributes = []) : bool
29
{
30
    $regex = path_regex($path);
31
    if (!preg_match($regex, $subject, $matches)) {
32
        return false;
33
    }
34
35
    $attributes = [];
36
    foreach ($matches as $key => $value) {
37
        if (!is_int($key) && '' !== $value) {
38
            $attributes[$key] = $value;
39
        }
40
    }
41
42
    return true;
43
}
44