CsrfBadge::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 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\Authenticator\Passport\Badge;
13
14
use Slick\WebStack\Domain\Security\Csrf\CsrfToken;
15
use Slick\WebStack\Domain\Security\Http\Authenticator\Passport\BadgeInterface;
16
17
/**
18
 * CsrfBadge
19
 *
20
 * @package Slick\WebStack\Domain\Security\Http\Authenticator\Passport\Badge
21
 */
22
final class CsrfBadge implements BadgeInterface
23
{
24
    private mixed $validatingFn;
25
    private CsrfToken $csrfToken;
26
27
    public function __construct(CsrfToken $csrfToken, callable $validatingFn)
28
    {
29
        $this->validatingFn = $validatingFn;
30
        $this->csrfToken = $csrfToken;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function isResolved(): bool
37
    {
38
        $function = $this->validatingFn;
39
        return $function($this->csrfToken);
40
    }
41
}
42