Completed
Push — master ( 8db26a...d97d4a )
by John
01:50
created

OneKeyAccessControl::validateKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace LunixREST\AccessControl;
3
use LunixREST\Request\Request;
4
5
/**
6
 * Class PublicAccessControl
7
 * @package LunixREST\AccessControl
8
 */
9
class OneKeyAccessControl implements AccessControl {
10
    /**
11
     * @var string
12
     */
13
    protected $key;
14
15
    /**
16
     * @param string $key
17
     */
18
    public function __construct($key){
19
        $this->key = $key;
20
    }
21
22
    /**
23
     * @param \LunixREST\Request\Request $request
24
     * @return bool true if key is valid
25
     */
26
    public function validateAccess(Request $request){
27
        return $this->validateKey($request->getApiKey());
28
    }
29
30
    /**
31
     * @param $apiKey
32
     * @return bool true if key is the key specified in the constructor
33
     */
34
    public function validateKey($apiKey){
35
        return $apiKey === $this->key;
36
    }
37
}
38