Completed
Push — master ( 1bfde5...2c00e3 )
by Peter
03:16
created

HandlerLocatedQueryDispatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Query\Dispatcher;
12
13
use GpsLab\Component\Query\Exception\HandlerNotFoundException;
14
use GpsLab\Component\Query\Handler\Locator\QueryHandlerLocator;
15
use GpsLab\Component\Query\Handler\QueryHandler;
16
use GpsLab\Component\Query\Query;
17
18
class HandlerLocatedQueryDispatcher implements QueryDispatcher
19
{
20
    /**
21
     * @var QueryHandlerLocator
22
     */
23
    private $locator;
24
25
    /**
26
     * @param QueryHandlerLocator $locator
27
     */
28 2
    public function __construct(QueryHandlerLocator $locator)
29
    {
30 2
        $this->locator = $locator;
31 2
    }
32
33
    /**
34
     * @param Query $query
35
     *
36
     * @return mixed
37
     */
38 2
    public function dispatch(Query $query)
39
    {
40 2
        $handler = $this->locator->getQueryHandler($query);
41
42 2
        if (!($handler instanceof QueryHandler)) {
43 1
            throw HandlerNotFoundException::notFound($query);
44
        }
45
46 1
        return $handler->handle($query);
47
    }
48
}
49