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 ( c03765...2f280c )
by Vermeulen
02:20
created

Module::loadModuleInstallInfos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 1
b 1
f 0
1
<?php
2
3
namespace BFW;
4
5
use \Exception;
6
use \stdClass;
7
8
class Module
9
{
10
    protected $pathName = '';
11
12
    protected $config;
13
14
    protected $installInfos;
15
16
    protected $loadInfos;
17
18
    protected $status;
19
20
    public function __construct($pathName, $loadModule = true)
21
    {
22
        $this->pathName = $pathName;
23
        
24
        if ($loadModule === true) {
25
            $this->loadModule();
26
        }
27
    }
28
    
29
    public function loadModule()
30
    {
31
        $this->status       = new stdClass();
32
        $this->status->load = false;
33
        $this->status->run  = false;
34
35
        $this->loadConfig();
36
        $this->loadModuleInstallInfos();
37
        $this->loadModuleInfos();
38
39
        $this->status->load = true;
40
    }
41
42
    public static function installInfos($pathName)
43
    {
44
        $module = new self($pathName, false);
45
        $module->loadModuleInstallInfos();
46
        
47
        return $module->getInstallInfos();
48
    }
49
50
    public function getPathName()
51
    {
52
        return $this->pathName;
53
    }
54
55
    public function getConfig()
56
    {
57
        return $this->config;
58
    }
59
60
    public function getInstallInfos()
61
    {
62
        return $this->installInfos;
63
    }
64
65
    public function getLoadInfos()
66
    {
67
        return $this->loadInfos;
68
    }
69
70
    public function getStatus()
71
    {
72
        return $this->status;
73
    }
74
75
    public function isLoaded()
76
    {
77
        return $this->status->load;
78
    }
79
80
    public function isRun()
81
    {
82
        return $this->status->run;
83
    }
84
85
    public function loadConfig()
86
    {
87
        if (!file_exists(CONFIG_DIR.$this->pathName)) {
88
            return;
89
        }
90
91
        $this->config = new \BFW\Config($this->pathName);
92
    }
93
94
    public function loadModuleInstallInfos()
95
    {
96
        $this->installInfos = $this->loadJsonFile(
97
            MODULES_DIR.$this->pathName.'/bfwModuleInstall.json'
98
        );
99
    }
100
101
    public function loadModuleInfos()
102
    {
103
        $this->loadInfos = $this->loadJsonFile(
104
            MODULES_DIR.$this->pathName
105
            .'/'.$this->installInfos->srcPath
106
            .'/modules.json'
107
        );
108
    }
109
110
    protected function loadJsonFile($jsonFilePath)
111
    {
112
        if (!file_exists($jsonFilePath)) {
113
            throw new Exception('File '.$jsonFilePath.' not found.');
114
        }
115
116
        $infos = json_decode(file_get_contents($jsonFilePath));
117
        if ($infos === null) {
118
            throw new Exception(json_last_error_msg());
119
        }
120
121
        return $infos;
122
    }
123
124
    protected function getRunnerFile()
125
    {
126
        $moduleInfos = $this->loadInfos;
127
        $runnerFile  = '';
128
129
        if (property_exists($moduleInfos, 'runner')) {
130
            $runnerFile = (string) $moduleInfos->runner;
131
        }
132
133
        if ($runnerFile === '') {
134
            return;
135
        }
136
137
        $runnerFile = MODULES_DIR.$this->pathName
138
            .'/'.$this->installInfos->srcPath
139
            .'/'.$runnerFile
140
        ;
141
142
        if (!file_exists($runnerFile)) {
143
            throw new Exception(
144
            'Runner file for module '.$this->pathName.' not found.'
145
            );
146
        }
147
148
        return $runnerFile;
149
    }
150
151
    public function runModule()
152
    {
153
        $runnerFile = $this->getRunnerFile();
154
155
        $initFunction = function() use ($runnerFile) {
156
            require(realpath($runnerFile));
157
        };
158
159
        $this->status->run = true;
160
        $initFunction();
161
    }
162
}
163