BaseDataStorage::validateKey()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Happyr\LinkedIn\Storage;
4
5
use Happyr\LinkedIn\Exception\InvalidArgumentException;
6
7
/**
8
 * @author Tobias Nyholm
9
 */
10
abstract class BaseDataStorage implements DataStorageInterface
11
{
12
    public static $validKeys = ['state', 'code', 'access_token', 'redirect_uri'];
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 1
    public function clearAll()
18
    {
19 1
        foreach (self::$validKeys as $key) {
20 1
            $this->clear($key);
21 1
        }
22 1
    }
23
24
    /**
25
     * Validate key. Throws an exception if key is not valid.
26
     *
27
     * @param string $key
28
     *
29
     * @throws InvalidArgumentException
30
     */
31 10
    protected function validateKey($key)
32
    {
33 10
        if (!in_array($key, self::$validKeys)) {
34 4
            throw new InvalidArgumentException('Unsupported key "%s" passed to LinkedIn data storage. Valid keys are: %s', $key, implode(', ', self::$validKeys));
35
        }
36 6
    }
37
38
    /**
39
     * Generate an ID to use with the data storage.
40
     *
41
     * @param $key
42
     *
43
     * @return string
44
     */
45 6
    protected function getStorageKeyId($key)
46
    {
47 6
        return 'linkedIn_'.$key;
48
    }
49
}
50