InMemoryCache::remove()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6667
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Innmind\RestBundle\Client\Server\Cache;
4
5
use Innmind\RestBundle\Client\Server\CacheInterface;
6
7
class InMemoryCache implements CacheInterface
8
{
9
    protected $data = [];
10
    protected $isFresh = false;
11
12
    /**
13
     * {@inheritdoc}
14
     */
15 12
    public function save($name, $url)
16
    {
17 12
        $this->data[(string) $name] = (string) $url;
18 12
        $this->isFresh = true;
19
20 12
        return $this;
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 10
    public function has($name)
27
    {
28 10
        return array_key_exists((string) $name, $this->data);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 10
    public function keys()
35
    {
36 10
        return array_keys($this->data);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 6
    public function get($name)
43
    {
44 6
        if (!$this->has($name)) {
45
            throw new \InvalidArgumentException(sprintf(
46
                'No resource named "%s" found',
47
                $name
48
            ));
49
        }
50
51 6
        return $this->data[(string) $name];
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 4
    public function remove($name)
58
    {
59 4
        if ($this->has($name)) {
60 4
            unset($this->data[(string) $name]);
61 4
            $this->isFresh = true;
62 4
        }
63
64 4
        return $this;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 6
    public function isFresh()
71
    {
72 6
        return $this->isFresh;
73
    }
74
}
75