Completed
Push — 4.0 ( 0161d2...25fc97 )
by Marco
12:04
created

EventsManager::loadPlugins()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 6
nc 2
nop 1
1
<?php namespace Comodojo\Dispatcher\Events;
2
3
use \League\Event\Emitter;
4
5
/**
6
 * @package     Comodojo Dispatcher
7
 * @author      Marco Giovinazzi <[email protected]>
8
 * @author      Marco Castiello <[email protected]>
9
 * @license     GPL-3.0+
10
 *
11
 * LICENSE:
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
 */
26
27
28
class EventsManager extends Emitter {
29
30 View Code Duplication
    public function subscribe($event, $class, $method = null, $priority = 0) {
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...
31
32
        $callable = ( is_null($method) ) ? $class : array($class, $method);
33
34
        return $this->addListener($event, $callable, $priority);
35
36
    }
37
38 View Code Duplication
    public function subscribeOnce($event, $class, $method = null, $priority = 0) {
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...
39
40
        $callable = ( is_null($method) ) ? $class : array($class, $method);
41
42
        return $this->addOneTimeListener($event, $callable, $priority);
43
44
    }
45
46
    public function loadPlugins($plugins) {
47
48
        if ( !empty($plugins) ) {
49
50
            foreach( $plugins as $name => $event ) {
51
52
                $callable = ( is_null($event['method']) ) ? $event["class"] : array($event["class"], $event["method"]);
53
54
                $this->addListener($event["event"], $callable, $event["priority"]);
55
56
            }
57
58
        }
59
60
        return $this;
61
62
    }
63
64
}
65