BaseDataStorage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clearAll() 0 6 2
A validateKey() 0 6 2
A getStorageKeyId() 0 4 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 = ['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