DispatcherChain::dispatch()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
crap 3
1
<?php
2
3
namespace Mosaic\Routing\Dispatchers;
4
5
use Mosaic\Routing\Route;
6
7
class DispatcherChain implements Dispatcher
8
{
9
    /**
10
     * @var Dispatcher[]
11
     */
12
    private $dispatchers;
13
14
    /**
15
     * @param $dispatchers
16
     */
17 4
    public function __construct(Dispatcher ...$dispatchers)
18
    {
19 4
        $this->dispatchers = $dispatchers;
20 4
    }
21
22
    /**
23
     * @param  Route    $route
24
     * @param  callable $next
25
     * @return mixed
26
     */
27 4
    public function dispatch(Route $route, callable $next)
28
    {
29 4
        foreach ($this->dispatchers as $dispatcher) {
30 4
            $response = $dispatcher->dispatch($route, $next);
31
32 4
            if (!$response instanceof Route) {
33 4
                return $response;
34
            }
35
        }
36 1
    }
37
}
38