Completed
Push — master ( 21e214...2bd91c )
by Irfaq
02:34
created

EmitsEvents   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 65
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 14.29%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 0
dl 30
loc 65
ccs 3
cts 21
cp 0.1429
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A emitEvent() 14 14 4
B emitBatchOfEvents() 16 16 5
A getEventEmitter() 0 4 1
A setEventEmitter() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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