SecurityProfileTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 5
c 0
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A match() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of web-stack
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\WebStack\Domain\Security\Http\SecurityProfile;
13
14
use Psr\Http\Message\ServerRequestInterface;
15
16
/**
17
 * SecurityProfileTrait
18
 *
19
 * @package Slick\WebStack\Domain\Security\Http\SecurityProfile
20
 */
21
trait SecurityProfileTrait
22
{
23
24
    protected ?string $matchExp = null;
25
26
    /**
27
     * Checks if the given request matches the defined match expression.
28
     *
29
     * @param ServerRequestInterface $request The server request to match against.
30
     * @return bool Returns true if the request matches the match expression, false otherwise.
31
     */
32
    public function match(ServerRequestInterface $request): bool
33
    {
34
        $path = $request->getUri()->getPath();
35
        return $this->matchExp ? (bool) preg_match($this->matchExp, $path) : false;
36
    }
37
}
38