ModulesCache::remove()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/js-sandbox PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the
11
 * LICENSE file that was distributed with this source or visit
12
 * http://opensource.org/licenses/MIT
13
 */
14
15
16
namespace Pinepain\JsSandbox\Modules;
17
18
19
use OutOfBoundsException;
20
use OverflowException;
21
22
23
class ModulesCache implements ModulesCacheInterface
24
{
25
    /**
26
     * @var ModuleInterface[]
27
     */
28
    protected $modules = [];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function has(string $id): bool
34
    {
35
        return isset($this->modules[$id]);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 View Code Duplication
    public function get(string $id): ModuleInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        if (!isset($this->modules[$id])) {
44
            throw new OutOfBoundsException("Can not load module '$id' from cache");
45
        }
46
47
        return $this->modules[$id];
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function put(string $id, ModuleInterface $module)
54
    {
55
        if (isset($this->modules[$id])) {
56
            throw new OverflowException("Module '$id' is already stored in cache ");
57
        }
58
59
        $this->modules[$id] = $module;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 View Code Duplication
    public function remove(string $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        if (!isset($this->modules[$id])) {
68
            throw new OutOfBoundsException("Module '$id' does not exists in cache");
69
        }
70
71
        unset($this->modules[$id]);
72
    }
73
74
75
}
76