Completed
Pull Request — master (#6)
by Woody
01:57
created

Command::withOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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