Completed
Pull Request — master (#6)
by Woody
03:19
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
     * Get the currently defined options.
21
     *
22
     * @return OptionsInterface
23
     *
24
     * @throws CommandException
25
     *  If no options have been added to the command.
26
     */
27 2
    final public function options()
28
    {
29 2
        if (!$this->options) {
30 1
            throw CommandException::needsOptions($this);
31
        }
32
33 1
        return $this->options;
34
    }
35
36
    /**
37
     * Get a copy with new options.
38
     *
39
     * @param OptionsInterface $options
40
     *
41
     * @return static
42
     */
43 1
    final public function withOptions(OptionsInterface $options)
44
    {
45 1
        $copy = clone $this;
46 1
        $copy->options = $options;
47
48 1
        return $copy;
49
    }
50
}
51