DataCachers::hasCacher()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Thruster\Component\DataCacher;
4
5
use Thruster\Component\DataCacher\Exception\DataCacherNotFoundException;
6
7
/**
8
 * Class DataCachers
9
 *
10
 * @package Thruster\Component\DataCacher
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class DataCachers
14
{
15
    /**
16
     * @var DataCacher[]
17
     */
18
    protected $dataCachers;
19
20 3
    public function __construct()
21
    {
22 3
        $this->dataCachers = [];
23 3
    }
24
25
    /**
26
     * @param string     $cacherName
27
     * @param DataCacher $dataCacher
28
     *
29
     * @return $this
30
     */
31 1
    public function addCacher(string $cacherName, DataCacher $dataCacher) : self
32
    {
33 1
        $this->dataCachers[$cacherName] = $dataCacher;
34
35 1
        return $this;
36
    }
37
38
    /**
39
     * @param string $cacherName
40
     *
41
     * @return bool
42
     */
43 3
    public function hasCacher(string $cacherName) : bool
44
    {
45 3
        return array_key_exists($cacherName, $this->dataCachers);
46
    }
47
48
    /**
49
     * @param string $cacherName
50
     *
51
     * @return DataCacher
52
     */
53 2
    public function getCacher(string $cacherName) : DataCacher
54
    {
55 2
        if (false === $this->hasCacher($cacherName)) {
56 1
            throw new DataCacherNotFoundException($cacherName);
57
        }
58
59 1
        return $this->dataCachers[$cacherName];
60
    }
61
62
    /**
63
     * @param string $cacherName
64
     *
65
     * @return $this
66
     */
67 1
    public function removeCacher(string $cacherName) : self
68
    {
69 1
        unset($this->dataCachers[$cacherName]);
70
71 1
        return $this;
72
    }
73
74
    /**
75
     * @return DataCacher[]
76
     */
77 1
    public function getCachers()
78
    {
79 1
        return $this->dataCachers;
80
    }
81
82
    /**
83
     * @param DataCacher[] $dataCachers
84
     *
85
     * @return $this
86
     */
87 1
    public function setCachers($dataCachers)
88
    {
89 1
        $this->dataCachers = $dataCachers;
90
91 1
        return $this;
92
    }
93
}
94