Test Failed
Push — develop ( 1bc728...a00b17 )
by Edwin
03:32
created

ActionCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 39
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A get() 0 7 2
A has() 0 7 2
1
<?php
2
3
namespace ShopifyClient\Action;
4
5
use ShopifyClient\Exception\ClientException;
6
7
class ActionCollection {
8
    /**
9
     * @var array
10
     */
11
    private $items = [];
12
13
    /**
14
     * @param $name
15
     * @param ActionInterface $action
16
     */
17 5
    public function add($name, ActionInterface $action) {
18 5
        $this->items[$name] = $action;
19 5
    }
20
21
    /**
22
     * @param $name
23
     * @return ActionInterface
24
     * @throws ClientException
25
     */
26 133
    public function get($name): ActionInterface {
27 133
        if (!$this->has($name)) {
28 3
            throw new ClientException(sprintf('%s action does not exist.', $name));
29
        }
30
31 130
        return $this->items[$name];
32
    }
33
34
    /**
35
     * @param $name
36
     * @return bool
37
     */
38 133
    public function has($name): bool {
39 133
        if (!isset($this->items[$name])) {
40 4
            return false;
41
        }
42
43 130
        return true;
44
    }
45
}