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

OneKeyAccessControl   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

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