HandlerLocatedQueryBus::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011, Peter Gribanov
9
 * @license   http://opensource.org/licenses/MIT
10
 */
11
12
namespace GpsLab\Component\Query\Bus;
13
14
use GpsLab\Component\Query\Exception\HandlerNotFoundException;
15
use GpsLab\Component\Query\Handler\Locator\QueryHandlerLocator;
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 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 handle(Query $query)
39
    {
40 2
        $handler = $this->locator->findHandler($query);
41
42 2
        if (!is_callable($handler)) {
43 1
            throw HandlerNotFoundException::notFound($query);
44
        }
45
46 1
        return $handler($query);
47
    }
48
}
49