Completed
Pull Request — master (#73)
by Tobias
03:11 queued 51s
created

BaseDataStorage::validateKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
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 = array('state', 'code', 'access_token', 'redirect_uri');
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function clearAll()
18
    {
19
        foreach (self::$validKeys as $key) {
20
            $this->clear($key);
21
        }
22
    }
23
24
    /**
25
     * Validate key. Throws an exception if key is not valid.
26
     *
27
     * @param string $key
28
     *
29
     * @throws InvalidArgumentException
30
     */
31
    protected function validateKey($key)
32
    {
33
        if (!in_array($key, self::$validKeys)) {
34
            throw new InvalidArgumentException('Unsupported key "%s" passed to LinkedIn data storage. Valid keys are: %s', $key, implode(', ', self::$validKeys));
35
        }
36
    }
37
38
    /**
39
     * Generate an ID to use with the data storage.
40
     *
41
     * @param $key
42
     *
43
     * @return string
44
     */
45
    protected function getStorageKeyId($key)
46
    {
47
        return 'linkedIn_'.$key;
48
    }
49
}
50