Completed
Pull Request — master (#6)
by Woody
03:19
created

Command   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 46
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
execute() 0 1 ?
A options() 0 8 2
A withOptions() 0 7 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