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.
Completed
Push — 3.0 ( 09574d...fe672e )
by Vermeulen
02:00
created

Modules::addModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace BFW;
4
5
use \Exception;
6
7
/**
8
 * Class to manage all modules in the application
9
 */
10
class Modules
11
{
12
    /**
13
     * @var \BFW\Module[] All module instance
14
     */
15
    protected $modules = [];
16
17
    /**
18
     * @var array $loadTree The dependency tree for all modules
19
     */
20
    protected $loadTree = [];
21
22
    /**
23
     * Get attribute modules value
24
     * 
25
     * @return \BFW\Module[]
26
     */
27
    public function getModules()
28
    {
29
        return $this->modules;
30
    }
31
32
    /**
33
     * Get the dependency tree
34
     * 
35
     * @return array
36
     */
37
    public function getLoadTree()
38
    {
39
        return $this->loadTree;
40
    }
41
42
    /**
43
     * Add a module to the modules's list
44
     * And instantiate \BFW\Module for this module
45
     * 
46
     * @param string $moduleName The module's name
47
     * 
48
     * @return void
49
     */
50
    public function addModule($moduleName)
51
    {
52
        $this->modules[$moduleName] = new \BFW\Module($moduleName);
53
    }
54
55
    /**
56
     * Get the \BFW\Module instance for a module
57
     * 
58
     * @param string $moduleName The module's name
59
     * 
60
     * @return \BFW\Module
61
     * 
62
     * @throws Exception If the module is not found
63
     */
64
    public function getModule($moduleName)
65
    {
66
        if (!isset($this->modules[$moduleName])) {
67
            throw new Exception('Module '.$moduleName.' not found.');
68
        }
69
70
        return $this->modules[$moduleName];
71
    }
72
    
73
    /**
74
     * Read the "needMe" property for each module and add the dependency
75
     * 
76
     * @throws \Exception If the dependency is not find in application
77
     * 
78
     * @return void
79
     */
80
    public function readNeedMeDependencies()
81
    {
82
        foreach ($this->modules as $readModuleName => $module) {
83
            $loadInfos = $module->getLoadInfos();
84
            
85
            if (!property_exists($loadInfos, 'needMe')) {
86
                continue;
87
            }
88
            
89
            $needMe = (array) $loadInfos->needMe;
90
            foreach ($needMe as $needModuleName) {
91
                if (!isset($this->modules[$needModuleName])) {
92
                    throw new Exception(
93
                        'Module error: '.$readModuleName
94
                        .' need '.$needModuleName
95
                        .' but this module is not found.'
96
                    );
97
                }
98
                
99
                $this->modules[$needModuleName]->addDependency(
100
                    $readModuleName
101
                );
102
            }
103
        }
104
    }
105
106
    /**
107
     * Generate the dependency tree for all declared module
108
     * 
109
     * @return void
110
     */
111
    public function generateTree()
112
    {
113
        $tree = new \bultonFr\DependencyTree\DependencyTree;
114
115
        foreach ($this->modules as $moduleName => $module) {
116
            $priority = 0;
117
            $depends  = [];
118
119
            $loadInfos = $module->getLoadInfos();
120
            if (property_exists($loadInfos, 'priority')) {
121
                $priority = (int) $loadInfos->priority;
122
            }
123
            if (property_exists($loadInfos, 'require')) {
124
                $depends = (array) $loadInfos->require;
125
            }
126
127
            $tree->addDependency($moduleName, $priority, $depends);
128
        }
129
130
        $this->loadTree = $tree->generateTree();
131
    }
132
}
133