MessageDispatcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Werkspot\MessageBus;
4
5
use DateTimeImmutable;
6
use Werkspot\MessageBus\Bus\Bus;
7
use Werkspot\MessageBus\Bus\BusInterface;
8
use Werkspot\MessageBus\Message\AsynchronousMessage;
9
use Werkspot\MessageBus\Message\Message;
10
use Werkspot\MessageBus\MessageQueue\Priority;
11
12
final class MessageDispatcher implements MessageDispatcherInterface
13
{
14
    /**
15
     * @var Bus
16
     */
17
    private $bus;
18
19 4
    public function __construct(BusInterface $bus)
20
    {
21 4
        $this->bus = $bus;
0 ignored issues
show
Documentation Bug introduced by
$bus is of type Werkspot\MessageBus\Bus\BusInterface, but the property $bus was declared to be of type Werkspot\MessageBus\Bus\Bus. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
22 4
    }
23
24 2
    public function dispatchSynchronousMessage(
25
        $payload,
26
        string $destination,
27
        array $metadataCollection = []
28
    ): void {
29 2
        $this->bus->deliver(new Message($payload, $destination, $metadataCollection));
30 2
    }
31
32 2
    public function dispatchQueuedMessage(
33
        $payload,
34
        string $destination,
35
        array $metadataCollection = [],
36
        DateTimeImmutable $deliverAt = null,
37
        Priority $priority = null
38
    ): void {
39 2
        $this->bus->deliver(new AsynchronousMessage($payload, $destination, $metadataCollection, $deliverAt, $priority));
40 2
    }
41
}
42