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

ActionCollection::has()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 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
}