EmitsEvents::emitBatchOfEvents()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 0
cts 9
cp 0
rs 9.4222
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 30
1
<?php
2
3
namespace Telegram\Bot\Events;
4
5
use League\Event\Emitter;
6
use League\Event\EventInterface;
7
8
trait EmitsEvents
9
{
10
    /**
11
     * @var Emitter
12
     */
13
    private $eventEmitter;
14
15
    /**
16
     * @param EventInterface|string $event
17
     * @throws \InvalidArgumentException
18
     * @return bool true if emitted, false otherwise
19
     */
20 6 View Code Duplication
    private function emitEvent($event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22 6
        if (is_null($this->eventEmitter)) {
23 6
            return false;
24
        }
25
26
        if (!is_string($event) && !$event instanceof EventInterface) {
27
            throw new \InvalidArgumentException('Event must be either be of type "string" or instance of League\Event\EventInterface');
28
        }
29
30
        $this->eventEmitter->emit($event);
31
32
        return true;
33
    }
34
35
    /**
36
     * @param EventInterface[]|string[] $events
37
     * @throws \InvalidArgumentException
38
     * @return bool true if all emitted, false otherwise
39
     */
40 View Code Duplication
    private function emitBatchOfEvents(array $events)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        if (is_null($this->eventEmitter)) {
43
            return false;
44
        }
45
46
        foreach ($events as $e) {
47
            if (!is_string($e) && !$e instanceof EventInterface) {
48
                throw new \InvalidArgumentException('Event must be either be of type "string" or instance of League\Event\EventInterface');
49
            }
50
        }
51
52
        $this->emitBatchOfEvents($events);
53
54
        return true;
55
    }
56
57
    /**
58
     * @return Emitter
59
     */
60
    public function getEventEmitter()
61
    {
62
        return $this->eventEmitter;
63
    }
64
65
    /**
66
     * @param Emitter $eventEmitter
67
     */
68
    public function setEventEmitter($eventEmitter)
69
    {
70
        $this->eventEmitter = $eventEmitter;
71
    }
72
}
73