Completed
Push — master ( 241c72...3d34d4 )
by Woody
7s
created

Command::options()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Equip\Command;
4
5
/**
6
 * A general purpose command class.
7
 *
8
 * @since 1.3.0
9
 */
10
abstract class Command
11
{
12
    /**
13
     * @var OptionsInterface
14
     */
15
    private $options;
16
17
    /**
18
     * Execute the command using the current options.
19
     *
20
     * @return mixed
21
     */
22
    abstract public function execute();
23
24
    /**
25
     * Allow usage as a callable.
26
     *
27
     * @see Command::execute()
28
     *
29
     * @return mixed
30
     */
31 1
    final public function __invoke()
32
    {
33 1
        return $this->execute();
34
    }
35
36
    /**
37
     * Get the currently defined options.
38
     *
39
     * @return OptionsInterface
40
     *
41
     * @throws CommandException
42
     *  If no options have been added to the command.
43
     */
44 2
    final public function options()
45
    {
46 2
        if (!$this->options) {
47 1
            throw CommandException::needsOptions($this);
48
        }
49
50 1
        return $this->options;
51
    }
52
53
    /**
54
     * Get a copy with new options.
55
     *
56
     * @param Options $options
57
     *
58
     * @return static
59
     */
60 1
    final public function withOptions(Options $options)
61
    {
62 1
        $copy = clone $this;
63 1
        $copy->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options of type object<Equip\Command\Options> is incompatible with the declared type object<Equip\Command\OptionsInterface> of property $options.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
65 1
        return $copy;
66
    }
67
}
68