GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StaticEventDispatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 78
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __callStatic() 0 16 2
A setEventManager() 0 4 1
A getEventManager() 0 8 2
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Event
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Event;
16
17
use Phossa2\Event\Message\Message;
18
use Phossa2\Shared\Base\StaticAbstract;
19
use Phossa2\Event\Exception\BadMethodCallException;
20
use Phossa2\Event\Interfaces\EventManagerInterface;
21
22
/**
23
 * StaticEventDispatcher
24
 *
25
 * A static wrapper of EventDispatcher
26
 *
27
 * ```php
28
 * // attach
29
 * StaticEventDispatcher::attach('test', function() { echo 'test'; });
30
 *
31
 * // trigger
32
 * StaticEventDispatcher::trigger('test');
33
 * ```
34
 *
35
 * @package Phossa2\Event
36
 * @author  Hong Zhang <[email protected]>
37
 * @version 2.1.0
38
 * @since   2.0.0 added
39
 * @since   2.1.0 updated
40
 */
41
class StaticEventDispatcher extends StaticAbstract
42
{
43
    /**
44
     * slave event manager
45
     *
46
     * @var    EventManagerInterface[]
47
     * @access protected
48
     * @staticvar
49
     */
50
    protected static $event_manager = [];
51
52
    /**
53
     * default static scope
54
     *
55
     * @var    string
56
     * @access protected
57
     * @staticvar
58
     */
59
    protected static $static_scope = '__STATIC__';
60
61
    /**
62
     * Provides a static interface for event dispatcher's dynamic methods
63
     *
64
     * @param  string $name method name
65
     * @param  array $arguments arguments
66
     * @return mixed
67
     * @throws BadMethodCallException if method not found
68
     * @access public
69
     * @static
70
     * @internal
71
     */
72
    public static function __callStatic($name, array $arguments)
73
    {
74
        $mgr = static::getEventManager();
75
        if (method_exists($mgr, $name)) {
76
            return call_user_func_array([$mgr, $name], $arguments);
77
        }
78
79
        throw new BadMethodCallException(
80
            Message::get(
81
                Message::MSG_METHOD_NOTFOUND,
82
                $name,
83
                get_called_class()
84
            ),
85
            Message::MSG_METHOD_NOTFOUND
86
        );
87
    }
88
89
    /**
90
     * Set the inner event manager
91
     *
92
     * @param  EventManagerInterface $eventManager
93
     * @access public
94
     * @api
95
     * @static
96
     */
97
    public static function setEventManager(EventManagerInterface $eventManager)
98
    {
99
        self::$event_manager[get_called_class()] = $eventManager;
100
    }
101
102
    /**
103
     * Get the inner event manager
104
     *
105
     * @return EventManagerInterface $eventManager
106
     * @access public
107
     * @api
108
     * @static
109
     */
110
    public static function getEventManager()
111
    {
112
        if (!isset(self::$event_manager[get_called_class()])) {
113
            self::$event_manager[get_called_class()] =
114
                EventDispatcher::getShareable(static::$static_scope);
115
        }
116
        return self::$event_manager[get_called_class()];
117
    }
118
}
119