Passed
Push — test ( 72117a...df5f1b )
by Tom
11:49
created

Options::verify()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

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