AbstractStorage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validateKey() 0 8 3
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Storage;
12
13
use Cubiche\Core\Serializer\SerializerInterface;
14
use Cubiche\Core\Storage\Exception\InvalidKeyException;
15
16
/**
17
 * AbstractStorage class.
18
 *
19
 * @author Ivannis Suárez Jerez <[email protected]>
20
 */
21
abstract class AbstractStorage
22
{
23
    /**
24
     * @var SerializerInterface
25
     */
26
    protected $serializer;
27
28
    /**
29
     * AbstractStorage constructor.
30
     *
31
     * @param SerializerInterface $serializer
32
     */
33
    public function __construct(SerializerInterface $serializer)
34
    {
35
        $this->serializer = $serializer;
36
    }
37
38
    /**
39
     * Validates that a key is valid.
40
     *
41
     * @param int|string $key
42
     *
43
     * @return bool
44
     *
45
     * @throws InvalidKeyException If the key is invalid.
46
     */
47
    protected function validateKey($key)
48
    {
49
        if (!is_string($key) && !is_int($key)) {
50
            throw InvalidKeyException::forKey($key);
51
        }
52
53
        return true;
54
    }
55
}
56