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 ( afe539...dd669d )
by Vermeulen
02:14
created

Module::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace BFW;
4
5
use \Exception;
6
use \stdClass;
7
8
/**
9
 * Class to manage a module
10
 */
11
class Module
12
{
13
    /**
14
     * @var string $pathName Module's name
15
     */
16
    protected $pathName = '';
17
18
    /**
19
     * @var \BFW\Config $config Config object for this module
20
     */
21
    protected $config;
22
23
    /**
24
     * @var \stdClass $installInfos All install informations for this module
25
     */
26
    protected $installInfos;
27
28
    /**
29
     * @var \stdClass $loadInfos All informations about the module running
30
     */
31
    protected $loadInfos;
32
33
    /**
34
     *
35
     * @var \stdClass $status Load and run status
36
     */
37
    protected $status;
38
39
    /**
40
     * Constructor
41
     * Load all informations if $loadModule is true
42
     * 
43
     * @param string $pathName Module name
44
     * @param boolean $loadModule (default true) If run load information
45
     */
46
    public function __construct($pathName, $loadModule = true)
47
    {
48
        $this->pathName = $pathName;
49
        
50
        if ($loadModule === true) {
51
            $this->loadModule();
52
        }
53
    }
54
    
55
    /**
56
     * Load informations about the module
57
     * 
58
     * @return void
59
     */
60
    public function loadModule()
61
    {
62
        $this->status       = new stdClass();
63
        $this->status->load = false;
64
        $this->status->run  = false;
65
66
        $this->loadConfig();
67
        $this->loadModuleInfos();
68
69
        $this->status->load = true;
70
    }
71
72
    /**
73
     * Get installation informations
74
     * 
75
     * @param string $pathName The module name
0 ignored issues
show
Bug introduced by
There is no parameter named $pathName. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
76
     * 
77
     * @return \stdClass
78
     */
79
    public static function installInfos($sourceFiles)
80
    {
81
        $currentClass = get_called_class(); //Allow extends
82
        return $currentClass::loadJsonFile($sourceFiles.'/bfwModulesInfos.json');
83
    }
84
85
    /**
86
     * Get the module's name
87
     * 
88
     * @return string
89
     */
90
    public function getPathName()
91
    {
92
        return $this->pathName;
93
    }
94
95
    /**
96
     * Get the Config object which have config for this module
97
     * 
98
     * @return \BFW\Config
99
     */
100
    public function getConfig()
101
    {
102
        return $this->config;
103
    }
104
105
    /**
106
     * Get the installation informations
107
     * 
108
     * @return \stdClass
109
     */
110
    public function getInstallInfos()
111
    {
112
        return $this->installInfos;
113
    }
114
115
    /**
116
     * Get the load informations
117
     * 
118
     * @return \stdClass
119
     */
120
    public function getLoadInfos()
121
    {
122
        return $this->loadInfos;
123
    }
124
125
    /**
126
     * Get the status object for this module
127
     * 
128
     * @return \stdClass
129
     */
130
    public function getStatus()
131
    {
132
        return $this->status;
133
    }
134
135
    /**
136
     * Return the load status
137
     * 
138
     * @return boolean
139
     */
140
    public function isLoaded()
141
    {
142
        return $this->status->load;
143
    }
144
145
    /**
146
     * Return the run status
147
     * 
148
     * @return boolean
149
     */
150
    public function isRun()
151
    {
152
        return $this->status->run;
153
    }
154
155
    /**
156
     * Instantiate the Config object to obtains module's configuration
157
     * 
158
     * @return void
159
     */
160
    public function loadConfig()
161
    {
162
        if (!file_exists(CONFIG_DIR.$this->pathName)) {
163
            return;
164
        }
165
166
        $this->config = new \BFW\Config($this->pathName);
167
        $this->config->loadFiles();
168
    }
169
170
    /**
171
     * Get load information from json file
172
     * 
173
     * @return void
174
     */
175
    public function loadModuleInfos()
176
    {
177
        $currentClass = get_called_class(); //Allow extends
178
        
179
        $this->loadInfos = $currentClass::loadJsonFile(
180
            MODULES_DIR.$this->pathName
181
            .'/module.json'
182
        );
183
    }
184
185
    /**
186
     * Read a json file and return datas in json
187
     * 
188
     * @param string $jsonFilePath : The path to the file to read
189
     * 
190
     * @return mixed Json parsed datas
191
     * 
192
     * @throws Exception If the file is not found or for a json parser error
193
     */
194
    protected static function loadJsonFile($jsonFilePath)
195
    {
196
        if (!file_exists($jsonFilePath)) {
197
            throw new Exception('File '.$jsonFilePath.' not found.');
198
        }
199
200
        $infos = json_decode(file_get_contents($jsonFilePath));
201
        if ($infos === null) {
202
            throw new Exception(json_last_error_msg());
203
        }
204
205
        return $infos;
206
    }
207
208
    /**
209
     * Get path to the runner file
210
     * 
211
     * @return string
212
     * 
213
     * @throws Exception If the file not exists
214
     */
215
    protected function getRunnerFile()
216
    {
217
        $moduleInfos = $this->loadInfos;
218
        $runnerFile  = '';
219
220
        if (property_exists($moduleInfos, 'runner')) {
221
            $runnerFile = (string) $moduleInfos->runner;
222
        }
223
224
        if ($runnerFile === '') {
225
            return;
226
        }
227
228
        $runnerFile = MODULES_DIR.$this->pathName
229
            .'/'.$runnerFile
230
        ;
231
232
        if (!file_exists($runnerFile)) {
233
            throw new Exception(
234
                'Runner file for module '.$this->pathName.' not found.'
235
            );
236
        }
237
238
        return $runnerFile;
239
    }
240
241
    /**
242
     * Run the module in a closure
243
     * 
244
     * @return void
245
     */
246
    public function runModule()
247
    {
248
        $runnerFile = $this->getRunnerFile();
249
        $module     = $this;
250
251
        $initFunction = function() use ($runnerFile, $module) {
252
            if ($runnerFile === null) {
253
                return;
254
            }
255
            
256
            require(realpath($runnerFile));
257
        };
258
259
        $this->status->run = true;
260
        $initFunction();
261
    }
262
}
263