HandlerLocatedQueryBus   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 31
ccs 8
cts 8
cp 1
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
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