Completed
Push — master ( 6dbf1b...fb879b )
by Iqbal
02:51
created

QueryBus::dispatchNow()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Cqrs\Bus;
12
13
use Borobudur\Bus\Bus;
14
use Borobudur\Bus\Message\MessageInterface;
15
use Borobudur\Cqrs\Collection;
16
use Borobudur\Cqrs\Exception\InvalidArgumentException;
17
use Borobudur\Cqrs\Message\QueryInterface;
18
use Borobudur\Cqrs\ReadModel\ReadModelInterface;
19
20
/**
21
 * @author      Iqbal Maulana <[email protected]>
22
 * @created     8/19/15
23
 */
24
class QueryBus extends Bus
25
{
26
    const BUS_NAME = 'bus.query';
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getName()
32
    {
33
        return QueryBus::BUS_NAME;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     *
39
     * @return ReadModelInterface|Collection
40
     */
41
    public function dispatchNow(MessageInterface $query)
42
    {
43
        if (!$query instanceof QueryInterface) {
44
            throw new InvalidArgumentException(sprintf(
45
                'Query "%s" should implement \Borobudur\Cqrs\Message\QueryInterface',
46
                get_class($query)
47
            ));
48
        }
49
50
        $results = parent::dispatchNow($query);
0 ignored issues
show
Bug introduced by
The method dispatchNow() does not exist on Borobudur\Bus\Bus. Did you maybe mean dispatch()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
51
52
        if (null === $results) {
53
            return null;
54
        }
55
56
        return $results;
57
    }
58
59
60
}
61