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 ( de1771...791612 )
by Vermeulen
04:28
created

Application::installAllModules()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 10
nc 5
nop 0
1
<?php
2
3
namespace BFW\Install;
4
5
use \BFW\Helpers\Cli;
6
use \BFW\Install\ModuleInstall;
7
8
/**
9
 * Application class for install module script
10
 */
11
class Application extends \BFW\Application
12
{
13
    /**
14
     * @var \BFW\Install\ModuleInstall[] $modulesInstall Modules to install
15
     */
16
    protected static $modulesInstall = [];
17
    
18
    /**
19
     * Getter to static property modulesInstall
20
     * 
21
     * @return \BFW\Install\ModuleInstall[]
22
     */
23
    public static function getModulesInstall()
24
    {
25
        return self::$modulesInstall;
26
    }
27
    
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function initRequest()
32
    {
33
        return;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function initSession()
40
    {
41
        return;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function initErrors()
48
    {
49
        return;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function initCli()
56
    {
57
        return;
58
    }
59
    
60
    /**
61
     * Add a new module in the list to install
62
     * 
63
     * @param \BFW\Install\ModuleInstall $module
64
     * 
65
     * @return void
66
     */
67
    public static function addModuleInstall(ModuleInstall $module)
68
    {
69
        $moduleName = $module->getName();
70
        
71
        self::$modulesInstall[$moduleName] = $module;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    protected function declareRunSteps()
78
    {
79
        $this->runSteps = [
80
            [$this, 'loadMemcached'],
81
            [$this, 'loadAllModules'],
82
            [$this, 'installAllModules']
83
        ];
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function run()
90
    {
91
        $runTasks = $this->getSubjectForName('ApplicationTasks');
92
        
93
        $runTasks->setNotifyPrefix('BfwAppModulesInstall');
0 ignored issues
show
Bug introduced by
The method setNotifyPrefix() does not exist on BFW\Subjects. Did you maybe mean notify()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
94
        $runTasks->run();
95
        $runTasks->sendNotify('bfw_modules_install_done');
0 ignored issues
show
Bug introduced by
The method sendNotify() does not exist on BFW\Subjects. Did you maybe mean notify()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
96
    }
97
    
98
    /**
99
     * Install all modules in the order of the dependency tree.
100
     * 
101
     * @return void
102
     */
103
    protected function installAllModules()
104
    {
105
        Cli::displayMsgNL('Read all modules to run install script...');
106
        
107
        $tree = $this->modules->getLoadTree();
108
109
        foreach ($tree as $firstLine) {
110
            foreach ($firstLine as $secondLine) {
111
                foreach ($secondLine as $moduleName) {
112
                    if (!isset(self::$modulesInstall[$moduleName])) {
113
                        continue;
114
                    }
115
                    
116
                    $this->installModule($moduleName);
117
                }
118
            }
119
        }
120
        
121
        Cli::displayMsgNL('All modules have been read.');
122
    }
123
    
124
    /**
125
     * Install a module
126
     * 
127
     * @param string $moduleName The module name
128
     * 
129
     * @return void
130
     */
131
    protected function installModule($moduleName)
132
    {
133
        if (!isset(self::$modulesInstall[$moduleName])) {
134
            return;
135
        }
136
        
137
        Cli::displayMsgNL(' > Read for module '.$moduleName);
138
        
139
        $module         = self::$modulesInstall[$moduleName];
140
        $installScripts = $module->getSourceInstallScript();
141
        
142
        if ($installScripts === '') {
143
            Cli::displayMsgNL(' >> No script to run.');
144
            return;
145
        }
146
        
147
        if (is_string($installScripts)) {
148
            $installScripts = (array) $installScripts;
149
        }
150
        
151
        foreach ($installScripts as $scriptPath) {
0 ignored issues
show
Bug introduced by
The expression $installScripts of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
152
            $module->runInstallScript($scriptPath);
153
        }
154
    }
155
}
156