StaticValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
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
}