Completed
Push — master ( cd9c3b...f127f4 )
by Woody
8s
created

AbstractCommand::defaultOptions()   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 0
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
            foreach ($required as $key) {
21 2
                if (!isset($this->options[$key])) {
22 1
                    throw CommandException::missingOption($key);
23
                }
24 1
            }
25 2
        }
26
27 3
        $this->options += $this->defaultOptions();
28
29 3
        return $this->options;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 3
    public function withOptions(array $options)
36
    {
37 3
        $copy = clone $this;
38 3
        $copy->options = $options;
39
40 3
        return $copy;
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 1
    public function addOptions(array $options)
47
    {
48 1
        $copy = clone $this;
49 1
        $copy->options = array_replace($copy->options, $options);
50
51 1
        return $copy;
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57 1
    public function hasOption($name)
58
    {
59 1
        return isset($this->options[$name]);
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 2
    public function defaultOptions()
66
    {
67 2
        return [];
68
    }
69
}
70