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 ( 572920...bfe862 )
by Vermeulen
02:24
created

Application::addModuleInstall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace BFW\Install;
4
5
use \BFW\Install\ModuleInstall;
6
7
/**
8
 * Application class for install module script
9
 */
10
class Application extends \BFW\Application
11
{
12
    /**
13
     * @var \BFW\Install\ModuleInstall[] $modulesInstall Modules to install
14
     */
15
    protected static $modulesInstall = [];
16
    
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function initRequest()
21
    {
22
        return;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function initSession()
29
    {
30
        return;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function initErrors()
37
    {
38
        return;
39
    }
40
    
41
    public static function addModuleInstall(ModuleInstall $module)
42
    {
43
        $moduleName = $module->getName();
44
        
45
        self::$modulesInstall[$moduleName] = $module;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function declareRunSteps()
52
    {
53
        $this->runSteps = [
54
            [$this, 'loadMemcached'],
55
            [$this, 'readAllModules'],
56
            [$this, 'installModules']
57
        ];
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 View Code Duplication
    public function run()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        foreach ($this->runSteps as $action) {
66
            $action();
67
68
            $notifyAction = $action;
69
            if (is_array($action)) {
70
                $notifyAction = $action[1];
71
            }
72
73
            $this->notifyAction('bfw_modules_install_run_'.$notifyAction);
74
        }
75
76
        $this->notifyAction('bfw_modules_install_finish');
77
    }
78
    
79
    /**
80
     * Install all modules in the order of the dependency tree.
81
     * 
82
     * @return void
83
     */
84
    protected function installModules()
85
    {
86
        echo 'Read all modules to run install script :'."\n";
87
        
88
        $tree = $this->modules->getLoadTree();
89
90
        foreach ($tree as $firstLine) {
91
            foreach ($firstLine as $secondLine) {
92
                foreach ($secondLine as $moduleName) {
93
                    if (!isset(self::$modulesInstall[$moduleName])) {
94
                        continue;
95
                    }
96
                    
97
                    $this->installModule($moduleName);
98
                }
99
            }
100
        }
101
    }
102
    
103
    /**
104
     * Install a module
105
     * 
106
     * @param string $moduleName The module name
107
     * 
108
     * @return void
109
     */
110
    protected function installModule($moduleName)
111
    {
112
        if (!isset(self::$modulesInstall[$moduleName])) {
113
            return;
114
        }
115
        
116
        echo ' > Read for module '.$moduleName."\n";
117
        
118
        $module         = self::$modulesInstall[$moduleName];
119
        $installScripts = $module->getSourceInstallScript();
120
        
121
        if ($installScripts === '') {
122
            echo ' >> No script to run.'."\n";
123
            return;
124
        }
125
        
126
        if (is_string($installScripts)) {
127
            $installScripts = (array) $installScripts;
128
        }
129
        
130
        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...
131
            $module->runInstall($scriptPath);
132
        }
133
    }
134
}
135