Completed
Push — master ( 1ee813...70e19a )
by John
02:44
created

AllAccessListAccessControl::validateKey()   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 0
Metric Value
dl 0
loc 4
rs 10
c 0
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
 * Similar to OneKeyAccessControl, but takes in an array of valid keys to check against.
8
 * IMPORTANT: Only use for short lists. Anything longer should be built using something else.
9
 * Class AllAccessListAccessControl
10
 * @package LunixRESTBasics\AccessControl
11
 */
12
class AllAccessListAccessControl implements AccessControl
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $keys;
18
19
    /**
20
     * @param array $keys
21
     */
22 2
    public function __construct(Array $keys)
23
    {
24 2
        $this->keys = $keys;
25 2
    }
26
27
    /**
28
     * @param \LunixREST\APIRequest\APIRequest $request
29
     * @return bool true if key is valid
30
     */
31 1
    public function validateAccess(APIRequest $request)
32
    {
33 1
        return $this->validateKey($request->getApiKey());
34
    }
35
36
    /**
37
     * @param $apiKey
38
     * @return bool true if key is in the array passed to this object in it's construction
39
     */
40 2
    public function validateKey($apiKey)
41
    {
42 2
        return in_array($apiKey, $this->keys);
43
    }
44
}
45