Completed
Branch version2 (a24b39)
by John
03:03
created

OneKeyAccessControl::validateAccess()   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\APIRequest\APIRequest;
5
6
/**
7
 * An access control policy that allows a single key full access to the API.
8
 * Class OneKeyAccessControl
9
 * @package LunixREST\Server\AccessControl
10
 */
11
class OneKeyAccessControl implements AccessControl
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $key;
17
18
    /**
19
     * @param string $key
20
     */
21 4
    public function __construct($key)
22
    {
23 4
        $this->key = $key;
24 4
    }
25
26
    /**
27
     * @param \LunixREST\Server\APIRequest\APIRequest $request
28
     * @return bool true if key is valid
29
     */
30 2
    public function validateAccess(APIRequest $request): bool
31
    {
32 2
        return $this->validateKey($request->getApiKey());
33
    }
34
35
    /**
36
     * @param $apiKey
37
     * @return bool true if key is the key specified in the constructor
38
     */
39 4
    public function validateKey($apiKey): bool
40
    {
41 4
        return $apiKey === $this->key;
42
    }
43
}
44