Completed
Pull Request — master (#7)
by Adam
02:44
created

AbstractCommand::option()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Equip\Command;
4
5
abstract class AbstractCommand implements CommandInterface
6
{
7
    /**
8
     * @var array
9
     */
10
    private $options = [];
11
12
    /**
13
     * @inheritDoc
14
     */
15 4
    public function options()
16
    {
17 4
        $required = $this->requiredOptions();
18
19 4
        if ($required) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $required of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
20 2
            $missing = array_diff($required, array_keys($this->options));
21 2
            if ($missing) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $missing of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
22 1
                throw CommandException::missingOptions($missing);
23
            }
24 1
        }
25
26 3
        $this->options += $this->defaultOptions();
27
28 3
        return $this->options;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34 1
    public function option($name)
35
    {
36 1
        return $this->options[$name];
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42 4
    public function withOptions(array $options)
43
    {
44 4
        $copy = clone $this;
45 4
        $copy->options = $options;
46
47 4
        return $copy;
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53 1
    public function addOptions(array $options)
54
    {
55 1
        $copy = clone $this;
56 1
        $copy->options = array_replace($copy->options, $options);
57
58 1
        return $copy;
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64 1
    public function hasOption($name)
65
    {
66 1
        return isset($this->options[$name]);
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72 2
    public function defaultOptions()
73
    {
74 2
        return [];
75
    }
76
}
77