Completed
Push — feature/EVO-6305_worker_authen... ( 11e94e )
by Bastian
08:06
created

MultiStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 20%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 51
ccs 3
cts 15
cp 0.2
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A apply() 0 19 4
A stopPropagation() 0 3 1
1
<?php
2
/**
3
 * strategy combining a set of strategies to be applied
4
 */
5
6
namespace Graviton\SecurityBundle\Authentication\Strategies;
7
8
use Symfony\Component\HttpFoundation\Request;
9
10
/**
11
 * Class MultiStrategy
12
 *
13
 * @package Graviton\SecurityBundle\Authentication\Strategies
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class MultiStrategy implements StrategyInterface
19
{
20
    /** @var StrategyInterface[]  */
21
    protected $strategies;
22
23
    /**
24
     * MultiStrategy constructor.
25
     *
26
     * @param StrategyInterface[] $strategies
27
     */
28 4
    public function __construct(array $strategies)
29
    {
30 4
        $this->strategies = $strategies;
31 4
    }
32
33
    /**
34
     * Applies the defined strategies on the provided request.
35
     *
36
     * @param Request $request request to handle
37
     *
38
     * @return string
39
     */
40
    public function apply(Request $request)
41
    {
42
        $exceptions = [];
43
44
        foreach ($this->strategies as $strategy) {
45
            try {
46
                $name = $strategy->apply($request);
47
48
                if ($strategy->stopPropagation()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
49
50
                    return $name;
51
                }
52
            } catch ( \InvalidArgumentException $e) {
53
                $exceptions[] = $e;
54
            }
55
        }
56
57
        throw new \InvalidArgumentException($exceptions[0]->getMessage(), $exceptions[0]);
58
    }
59
60
    /**
61
     * Decider to stop other strategies running after from being considered.
62
     *
63
     * @return boolean
64
     */
65
    public function stopPropagation() {
66
        return false;
67
    }
68
}
69