HasEvents   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 6
eloc 9
c 4
b 0
f 2
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEvent() 0 5 2
A setEvents() 0 2 1
A setEvent() 0 3 2
A getEvents() 0 2 1
1
<?php
2
/*
3
* File: HasEvents.php
4
* Category: -
5
* Author: M.Goldenbaum
6
* Created: 21.09.20 22:46
7
* Updated: -
8
*
9
* Description:
10
*  -
11
*/
12
13
namespace Webklex\PHPIMAP\Traits;
14
15
16
use Webklex\PHPIMAP\Events\Event;
17
use Webklex\PHPIMAP\Exceptions\EventNotFoundException;
18
19
/**
20
 * Trait HasEvents
21
 *
22
 * @package Webklex\PHPIMAP\Traits
23
 */
24
trait HasEvents {
25
26
    /**
27
     * Event holder
28
     *
29
     * @var array $events
30
     */
31
    protected $events = [];
32
33
    /**
34
     * Set a specific event
35
     * @param $section
36
     * @param $event
37
     * @param $class
38
     */
39
    public function setEvent($section, $event, $class) {
40
        if (isset($this->events[$section])) {
41
            $this->events[$section][$event] = $class;
42
        }
43
    }
44
45
    /**
46
     * Set all events
47
     * @param $events
48
     */
49
    public function setEvents($events) {
50
        $this->events = $events;
51
    }
52
53
    /**
54
     * Get a specific event callback
55
     * @param $section
56
     * @param $event
57
     *
58
     * @return Event|string
59
     * @throws EventNotFoundException
60
     */
61
    public function getEvent($section, $event) {
62
        if (isset($this->events[$section])) {
63
            return $this->events[$section][$event];
64
        }
65
        throw new EventNotFoundException();
66
    }
67
68
    /**
69
     * Get all events
70
     *
71
     * @return array
72
     */
73
    public function getEvents(): array {
74
        return $this->events;
75
    }
76
77
}