Completed
Push — master ( 7de3b3...4f8d98 )
by Woody
16:48 queued 39s
created

AbstractCommand::hasOption()   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
Metric Value
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 3
    public function options()
16
    {
17 3
        $required = $this->requiredOptions();
18
19 3
        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 2
        return $this->options;
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33 3
    public function withOptions(array $options)
34
    {
35 3
        $copy = clone $this;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36 3
        $copy->options = $options;
37
38 3
        return $copy;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44 1
    public function addOptions(array $options)
45
    {
46 1
        $copy = clone $this;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
47 1
        $copy->options = array_replace($copy->options, $options);
48
49 1
        return $copy;
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55 1
    public function hasOption($name)
56
    {
57 1
        return isset($this->options[$name]);
58
    }
59
}
60