Completed
Push — master ( 5acd24...5c27f0 )
by John
14s
created

KeyRepositoryAccessControl::validateKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace LunixREST\Server\AccessControl;
3
4
use LunixREST\Server\AccessControl\KeyRepository\KeyRepository;
5
6
/**
7
 * An access control that relies on a key repository. Any keys in the repository are valid.
8
 * Class KeyRepositoryAccessControl
9
 * @package LunixREST\Server\AccessControl
10
 */
11
abstract class KeyRepositoryAccessControl implements AccessControl
12
{
13
    /**
14
     * @var KeyRepository
15
     */
16
    private $keyRepository;
17
18
    /**
19
     * KeyRepositoryAccessControl constructor.
20
     * @param KeyRepository $keyRepository
21
     */
22 6
    public function __construct(KeyRepository $keyRepository)
23
    {
24 6
        $this->keyRepository = $keyRepository;
25 6
    }
26
27
    /**
28
     * @param $apiKey
29
     * @return bool
30
     */
31 6
    public function validateKey($apiKey): bool
32
    {
33 6
        return $this->keyRepository->hasKey($apiKey);
34
    }
35
}
36