BusHelper::setHelperSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * (c) 2018 Douglas Reith.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace Reith\ToyRobot\Console;
12
13
use Symfony\Component\Console\Helper\HelperInterface;
14
use Symfony\Component\Console\Helper\HelperSet;
15
use Reith\ToyRobot\Messaging\BusInterface;
16
17
class BusHelper implements HelperInterface
18
{
19
    private $helperSet;
20
21
    private $commandBus;
22
23
    private $queryBus;
24
25 7
    public function setCommandBus(BusInterface $commandBus): BusHelper
26
    {
27 7
        $this->commandBus = $commandBus;
28
29 7
        return $this;
30
    }
31
32 7
    public function setQueryBus(BusInterface $queryBus): BusHelper
33
    {
34 7
        $this->queryBus = $queryBus;
35
36 7
        return $this;
37
    }
38
39 13
    public function setHelperSet(HelperSet $helperSet = null)
40
    {
41 13
        $this->helperSet = $helperSet;
42
43 13
        return $this;
44
    }
45
46
    /**
47
     * Gets the helper set associated with this helper.
48
     *
49
     * @return HelperSet A HelperSet instance
50
     */
51
    public function getHelperSet()
52
    {
53
        return $this->helperSet;
54
    }
55
56
    /**
57
     * Returns the canonical name of this helper.
58
     *
59
     * @return string The canonical name
60
     */
61 13
    public function getName()
62
    {
63 13
        return 'bus';
64
    }
65
66
    /**
67
     * @param mixed $message
68
     *
69
     * @throws \RuntimeException
70
     */
71 5
    public function postCommand($message): void
72
    {
73 5
        if (!$this->commandBus) {
74
            throw new \RuntimeException(
75
                'Command bus is not configured'
76
            );
77
        }
78
79 5
        $this->commandBus->post($message);
80 5
    }
81
82
    /**
83
     * @param mixed     $message
84
     * @param ?callable $callback To get response data
0 ignored issues
show
Documentation introduced by
The doc-type ?callable could not be parsed: Unknown type name "?callable" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
85
     *
86
     * @throws \RuntimeException
87
     */
88 5
    public function postQuery($message, ?callable $callback = null): void
89
    {
90 5
        if (!$this->queryBus) {
91
            throw new \RuntimeException(
92
                'Query bus is not configured'
93
            );
94
        }
95
96 5
        $this->queryBus->post($message, $callback);
0 ignored issues
show
Unused Code introduced by
The call to BusInterface::post() has too many arguments starting with $callback.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
97 5
    }
98
}
99