Passed
Push — test ( 8d4b30...f689e2 )
by Tom
02:36
created

RunOpts::getOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Runner;
6
7
use Ktomk\Pipelines\Utility\Options;
8
9
/**
10
 * Runner options parameter object
11
 */
12
class RunOpts
13
{
14
    /**
15
     * @var string
16
     */
17
    private $prefix;
18
19
    /**
20
     * @var Options
21
     */
22
    private $options;
23
24
    /**
25
     * Static factory method
26
     *
27
     * @param string $prefix [optional]
28
     *
29
     * @return RunOpts
30
     */
31 1
    public static function create($prefix = null)
32
    {
33 1
        return new self($prefix, Options::create());
34
    }
35
36
    /**
37
     * RunOpts constructor.
38
     *
39
     * NOTE: All run options are optional by design (pass NULL).
40
     *
41
     * @param string $prefix
42
     * @param null|Options $options
43
     */
44 2
    public function __construct($prefix = null, Options $options = null)
45
    {
46 2
        $this->prefix = $prefix;
47 2
        $this->options = $options;
48 2
    }
49
50
    /**
51
     * @param string $prefix
52
     */
53 1
    public function setPrefix($prefix)
54
    {
55 1
        $this->prefix = $prefix;
56 1
    }
57
58
    /**
59
     * The prefix is used when creating containers for the container name.
60
     *
61
     * See --prefix option.
62
     *
63
     * @return string
64
     */
65 1
    public function getPrefix()
66
    {
67 1
        return $this->prefix;
68
    }
69
70
    /**
71
     * @param string $name
72
     *
73
     * @return null|string
74
     */
75 2
    public function getOption($name)
76
    {
77 2
        if (!isset($this->options)) {
78 1
            return null;
79
        }
80
81 1
        return $this->options->get($name);
82
    }
83
}
84