EmitterTrait::emit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
namespace EventIO\InterOp;
3
4
/**
5
 * Trait EmitterTrait
6
 * @package EventIO\InterOp
7
 */
8
trait EmitterTrait
9
{
10
    /**
11
     * @param array ...$events The event triggered
12
     * @return mixed
13
     */
14
    public function emit(...$events)
15
    {
16
        foreach ($events as $event) {
17
            $this->parseEvent($event);
0 ignored issues
show
Documentation introduced by
$event is of type array, but the function expects a string|object<EventIO\InterOp\EventInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
18
        }
19
    }
20
21
    /**
22
     * @param EventInterface $event An event to emit
23
     * @return mixed
24
     */
25
    abstract public function emitEvent(EventInterface $event);
26
27
    /**
28
     * @param string $event An event name
29
     * @return mixed
30
     */
31
    abstract public function emitName($event);
32
33
    /**
34
     * @param string|EventInterface $event An event received
35
     * @return mixed
36
     */
37
    private function parseEvent($event)
38
    {
39
        if ($event instanceof EventInterface) {
40
            return $this->emitEvent($event);
41
        }
42
43
        return $this->emitName($event);
44
    }
45
}
46