Completed
Push — master ( 4a47c7...5ddc50 )
by John
02:05
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 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 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