ListStrategy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 11 3
1
<?php
2
namespace Nubs\Sensible\Strategy;
3
4
/**
5
 * Executes each strategy in turn until one of them returns a non-null result.
6
 */
7
class ListStrategy implements StrategyInterface
8
{
9
    /** @type \Nubs\Sensible\StrategyInterface[] The strategies to use. */
10
    private $_strategies;
11
12
    /**
13
     * Initialize the strategy to wrap a list of alternate strategies.
14
     *
15
     * @param \Nubs\Sensible\StrategyInterface[] $strategies The strategies to
16
     *     use.
17
     */
18
    public function __construct(array $strategies)
19
    {
20
        $this->_strategies = $strategies;
21
    }
22
23
    /**
24
     * Returns the result of the first successful strategy.
25
     *
26
     * @return string|null The command as located by a strategy or null if no
27
     *     strategies found a command to use.
28
     */
29
    public function get()
30
    {
31
        foreach ($this->_strategies as $strategy) {
32
            $result = $strategy->get();
33
            if ($result !== null) {
34
                return $result;
35
            }
36
        }
37
38
        return null;
39
    }
40
}
41