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

OneKeyAccessControl   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validateAccess() 0 4 1
A validateKey() 0 4 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