Passed
Push — master ( 72117a...c610db )
by Tom
14:09 queued 10:33
created

Options   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 3
Metric Value
eloc 16
c 3
b 0
f 3
dl 0
loc 58
ccs 16
cts 16
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 5 3
A create() 0 10 1
A get() 0 7 2
A __construct() 0 4 1
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Utility;
6
7
use Ktomk\Pipelines\Utility\Option\Types;
8
9
/**
10
 * application options store
11
 */
12
class Options
13
{
14
    /**
15
     * @var array protected to make use of it in OptionsMock for tests
16
     */
17
    protected $definition;
18
19
    /**
20
     * @var Types used in the definition
21
     */
22
    protected $types;
23
24
    /**
25
     * @return Options
26
     */
27 4
    public static function create()
28
    {
29 4
        $definition = array(
30 4
            'docker.socket.path' => array('/var/run/docker.sock', null),
31
            'docker.client.path' => array('/usr/bin/docker', null),
32
            'script.exit-early' => array(false, null),
33 4
            'step.clone-path' => array('/app', Types::ABSPATH),
34
        );
35
36 4
        return new self($definition, new Types());
37
    }
38
39 4
    public function __construct(array $definition, Types $types = null)
40
    {
41 4
        $this->definition = $definition;
42 4
        $this->types = $types;
43 4
    }
44
45
    /**
46
     * @param string $name
47
     *
48
     * @return null|bool|string
49
     */
50 2
    final public function get($name)
51
    {
52 2
        if (isset($this->definition[$name][0])) {
53 2
            return $this->definition[$name][0];
54
        }
55
56 2
        return null;
57
    }
58
59
    /**
60
     * @param string $name
61
     * @param string $value
62
     *
63
     * @return null|string
64
     */
65 2
    final public function verify($name, $value)
66
    {
67 2
        $type = isset($this->definition[$name][1]) ? $this->definition[$name][1] : null;
68
69 2
        return $this->types  ? $this->types->verifyInput($value, $type) : $value;
70
    }
71
}
72