EventManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B getList() 0 17 5
1
<?php
2
3
namespace yiicod\socketio;
4
5
use Yii;
6
use yii\base\Component;
7
use yii\helpers\Json;
8
9
class EventManager extends Component
10
{
11
    /**
12
     * Array of events namespaces
13
     *
14
     * @var array
15
     */
16
    public $namespaces = [];
17
18
    /**
19
     * You can set unique nsp for channels
20
     *
21
     * @var string
22
     */
23
    public $nsp = '';
24
25
    /**
26
     * List with all events
27
     *
28
     * @var array
29
     */
30
    protected static $list = [];
31
32
    public function getList(): array
33
    {
34
        if (empty(static::$list)) {
35
            foreach ($this->namespaces as $key => $namespace) {
36
                $alias = Yii::getAlias('@' . str_replace('\\', '/', trim($namespace, '\\')));
37
                foreach (glob(sprintf('%s/**.php', $alias)) as $file) {
38
                    $className = sprintf('%s\%s', $namespace, basename($file, '.php'));
39
                    if (method_exists($className, 'name')) {
40
                        static::$list[$className::name()] = $className;
41
                    }
42
                }
43
            }
44
            //Yii::info(Json::encode(static::$list));
45
        }
46
47
        return static::$list;
48
    }
49
}
50