AbstractCommandOption   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 3 1
A add() 0 3 1
A get() 0 13 2
1
<?php
2
3
namespace Jackal\ImageMerge\Command\Options;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Class AbstractCommandOption
9
 * @package Jackal\ImageMerge\Command\Options
10
 */
11
abstract class AbstractCommandOption implements CommandOptionInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $options = [];
17
18
    /**
19
     * @param $key
20
     * @param $value
21
     */
22
    public function add($key, $value)
23
    {
24
        $this->options[$key] = $value;
25
    }
26
27
    /**
28
     * @param $key
29
     * @return mixed
30
     */
31
    public function get($key)
32
    {
33
        if (!array_key_exists($key, $this->options)) {
34
            throw new InvalidArgumentException(
35
                sprintf('Key %s is not valid, available options are: %s',
36
                    $key,
37
                    implode(',', array_keys($this->options)
38
                    )
39
                )
40
            );
41
        }
42
43
        return $this->options[$key];
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    public function all()
50
    {
51
        return $this->options;
52
    }
53
}
54