Completed
Push — master ( 4a47c7...5ddc50 )
by John
02:05
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 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 1
b 0
f 0
ccs 7
cts 7
cp 1

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\AccessControl;
3
4
use LunixREST\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\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\APIRequest\APIRequest $request
28
     * @return bool true if key is valid
29
     */
30 2
    public function validateAccess(APIRequest $request)
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)
40
    {
41 4
        return $apiKey === $this->key;
42
    }
43
}
44