HasCacheTrait::getCache()   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 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Nip\Form\Traits;
4
5
/**
6
 * Trait HasCacheTrait
7
 * @package Nip\Form\Traits
8
 */
9
trait HasCacheTrait
10
{
11
    protected $_cache;
12
13
    /**
14
     * @param $key
15
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
16
     * @return mixed
17
     */
18 11
    public function getCache($key, $default = null)
19
    {
20 11
        if (!isset($this->_cache[$key])) {
21 11
            return $default;
22
        }
23 6
        return $this->_cache[$key];
24
    }
25
26
    /**
27
     * @param string $key
28
     * @param $value
29
     */
30 11
    public function setCache($key, $value)
31
    {
32 11
        $this->_cache[$key] = $value;
33 11
    }
34
35
    /**
36
     * @param $key
37
     * @return bool
38
     */
39
    public function isCache($key)
40
    {
41
        return isset($this->_cache[$key]);
42
    }
43
}
44