BroadcastEventMessage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
/*
3
 * This file is part of the Borobudur-Bus 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\EventSourcing;
12
13
use Borobudur\Broadcasting\BroadcastEventInterface;
14
use Borobudur\Broadcasting\BroadcastEventTrait;
15
16
/**
17
 * @author      Iqbal Maulana <[email protected]>
18
 * @created     9/16/15
19
 */
20
class BroadcastEventMessage implements BroadcastEventInterface
21
{
22
    use BroadcastEventTrait;
23
24
    /**
25
     * @var array
26
     */
27
    public $message;
28
29
    /**
30
     * @var array
31
     */
32
    public $metadata;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param BroadcastEventInterface $event
38
     * @param array                   $metadata
39
     */
40
    public function __construct(BroadcastEventInterface $event, array $metadata)
41
    {
42
        $this->setBroadcastName($event->getBroadcastName());
43
        $this->setBroadcastChannel($event->getBroadcastChannels());
44
        $this->message = $event->getBroadcastPayload();
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->getBroadcastPayload() can be null. However, the property $message is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
45
        $this->metadata = $metadata;
46
    }
47
}
48