StaticValidator::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Service\Middleware\Security\Validator;
6
7
8
use Xervice\Service\Middleware\Security\Exception\AuthenticationFailed;
9
10
class StaticValidator implements ValidatorInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $tokenList;
16
17
    /**
18
     * StaticTokenValidator constructor.
19
     *
20
     * @param array $tokenList
21
     */
22
    public function __construct(array $tokenList)
23
    {
24
        $this->tokenList = $tokenList;
25
    }
26
27
    /**
28
     * @param string $token
29
     *
30
     * @throws \Xervice\Service\Middleware\Security\Exception\AuthenticationFailed
31
     */
32
    public function validate(string $token): void
33
    {
34
        if (!in_array($token, $this->tokenList)) {
35
            throw new AuthenticationFailed();
36
        }
37
    }
38
}