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.

ModuleList   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 146
rs 10
c 0
b 0
f 0
wmc 17

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A runModule() 0 11 1
A getModuleList() 0 3 1
A toRun() 0 3 1
A run() 0 7 1
A runAllAppModules() 0 8 4
A loadAllModules() 0 16 3
A __invoke() 0 3 1
A runAllCoreModules() 0 16 4
1
<?php
2
3
namespace BFW\Core\AppSystems;
4
5
class ModuleList extends AbstractSystem
6
{
7
    /**
8
     * @var \BFW\Core\ModuleList $moduleList
9
     */
10
    protected $moduleList;
11
    
12
    /**
13
     * Initialize the ModuleList system
14
     */
15
    public function __construct()
16
    {
17
        $this->moduleList = new \BFW\Core\ModuleList;
18
    }
19
    
20
    /**
21
     * {@inheritdoc}
22
     * 
23
     * @return \BFW\Core\ModuleList
24
     */
25
    public function __invoke()
26
    {
27
        return $this->moduleList;
28
    }
29
30
    /**
31
     * Getter accessor to property moduleList
32
     * 
33
     * @return \BFW\Core\ModuleList
34
     */
35
    public function getModuleList()
36
    {
37
        return $this->moduleList;
38
    }
39
    
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function toRun(): bool
44
    {
45
        return true;
46
    }
47
    
48
    /**
49
     * {@inheritdoc}
50
     * 
51
     * Load all modules, run all core and app modules
52
     */
53
    public function run()
54
    {
55
        $this->loadAllModules();
56
        $this->runAllCoreModules();
57
        $this->runAllAppModules();
58
        
59
        $this->runStatus = true;
60
    }
61
    
62
    /**
63
     * Read all directories in modules directory and add each module to Modules
64
     * class.
65
     * Generate the load tree.
66
     * Not initialize modules !
67
     * 
68
     * @return void
69
     */
70
    protected function loadAllModules()
71
    {
72
        $listModules = array_diff(scandir(MODULES_ENABLED_DIR), ['.', '..']);
0 ignored issues
show
Bug introduced by
It seems like scandir(BFW\Core\AppSystems\MODULES_ENABLED_DIR) can also be of type false; however, parameter $array1 of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
        $listModules = array_diff(/** @scrutinizer ignore-type */ scandir(MODULES_ENABLED_DIR), ['.', '..']);
Loading history...
Bug introduced by
The constant BFW\Core\AppSystems\MODULES_ENABLED_DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
73
74
        foreach ($listModules as $moduleName) {
75
            $modulePath = realpath(MODULES_ENABLED_DIR.$moduleName); //Symlink
76
77
            if (!is_dir($modulePath)) {
78
                continue;
79
            }
80
81
            $this->moduleList->addModule($moduleName);
82
        }
83
84
        $this->moduleList->readNeedMeDependencies();
85
        $this->moduleList->generateTree();
86
    }
87
88
    /**
89
     * Load core modules defined into config bfw file.
90
     * Only module for controller, router, database and template only.
91
     * 
92
     * @return void
93
     */
94
    protected function runAllCoreModules()
95
    {
96
        $allModules = \BFW\Application::getInstance()
97
            ->getConfig()
98
            ->getValue('modules', 'modules.php')
99
        ;
100
        
101
        foreach ($allModules as $moduleInfos) {
102
            $moduleName    = $moduleInfos['name'];
103
            $moduleEnabled = $moduleInfos['enabled'];
104
105
            if (empty($moduleName) || $moduleEnabled === false) {
106
                continue;
107
            }
108
109
            $this->runModule($moduleName);
110
        }
111
    }
112
113
    /**
114
     * Load all modules (except core).
115
     * Get the load tree, read him and load all modules with the order
116
     * declared into the tree.
117
     * 
118
     * @return void
119
     */
120
    protected function runAllAppModules()
121
    {
122
        $tree = $this->moduleList->getLoadTree();
123
124
        foreach ($tree as $firstLine) {
125
            foreach ($firstLine as $secondLine) {
126
                foreach ($secondLine as $moduleName) {
127
                    $this->runModule($moduleName);
128
                }
129
            }
130
        }
131
    }
132
133
    /**
134
     * Load a module
135
     * 
136
     * @param string $moduleName The module's name to load
137
     * 
138
     * @return void
139
     */
140
    protected function runModule(string $moduleName)
141
    {
142
        $app = \BFW\Application::getInstance();
143
        
144
        $app->getSubjectList()
145
            ->getSubjectByName('ApplicationTasks')
146
            ->sendNotify('BfwApp_run_module_'.$moduleName);
147
        
148
        $this->moduleList
149
            ->getModuleByName($moduleName)
150
            ->runModule();
151
    }
152
}
153