CommandFactoryTrait::getCommand()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
<?php
2
namespace Nubs\Sensible\CommandFactory;
3
4
use Exception;
5
use Nubs\Sensible\Strategy\StrategyInterface;
6
7
/**
8
 * Defines common methods for a command factory to use.
9
 */
10
trait CommandFactoryTrait
11
{
12
    /**
13
     * Execute the strategy and return the command.
14
     *
15
     * @param \Nubs\Sensible\Strategy\StrategyInterface $strategy The strategy
16
     *     to locate a command with.
17
     * @return string The command to execute.
18
     * @throws \Exception if the strategy fails to find a command.
19
     */
20
    protected function getCommand(StrategyInterface $strategy)
21
    {
22
        $command = $strategy->get();
23
        if ($command === null) {
24
            throw new Exception('Failed to locate a sensible command');
25
        }
26
27
        return $command;
28
    }
29
}
30