Completed
Push — master ( 6a1fcf...fe496e )
by Peter
09:07
created

HandlerLocatedQueryBus   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 10 2
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\Bus;
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 HandlerLocatedQueryBus implements QueryBus
19
{
20
    /**
21
     * @var QueryHandlerLocator
22
     */
23
    private $locator;
24
25
    /**
26
     * @param QueryHandlerLocator $locator
27
     */
28
    public function __construct(QueryHandlerLocator $locator)
29
    {
30
        $this->locator = $locator;
31
    }
32
33
    /**
34
     * @param Query $query
35
     *
36
     * @return mixed
37
     */
38
    public function handle(Query $query)
39
    {
40
        $handler = $this->locator->getQueryHandler($query);
41
42
        if (!($handler instanceof QueryHandler)) {
43
            throw HandlerNotFoundException::notFound($query);
44
        }
45
46
        return $handler->handle($query);
47
    }
48
}
49