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.

Bootstrap::init()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 39
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
rs 8.439
cc 6
eloc 23
nc 8
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace Test;
3
4
use Zend\Loader\AutoloaderFactory;
5
use Zend\Mvc\Service\ServiceManagerConfig;
6
use Zend\ServiceManager\ServiceManager;
7
use RuntimeException;
8
9
error_reporting(E_ALL | E_STRICT);
10
chdir(__DIR__);
11
12
class Bootstrap
13
{
14
    protected static $serviceManager;
15
    protected static $config;
16
    protected static $bootstrap;
17
18
    public static function init()
19
    {
20
        $zf2ModulePaths = array();
21
22
        if (isset($testConfig['module_listener_options']['module_paths'])) {
0 ignored issues
show
Bug introduced by
The variable $testConfig seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
23
            $modulePaths = $testConfig['module_listener_options']['module_paths'];
24
            foreach ($modulePaths as $modulePath) {
25
                if (($path = static::findParentPath($modulePath)) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
26
                    $zf2ModulePaths[] = $path;
27
                }
28
            }
29
        }
30
31
        $zf2ModulePaths  = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
32
        $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
33
34
        static::initAutoloader();
35
36
        // use ModuleManager to load this module and it's dependencies
37
        $config = array(
38
            'modules' => array(
39
                'ConsoleTools',
40
            ),
41
            'module_listener_options' => array(
42
                'module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths),
43
            ),
44
            'module_paths' => array(
45
                'module',
46
                'vendor',
47
            ),
48
        );
49
50
        $serviceManager = new ServiceManager(new ServiceManagerConfig());
51
        $serviceManager->setService('ApplicationConfig', $config);
52
        $serviceManager->get('ModuleManager')->loadModules();
53
54
        static::$serviceManager = $serviceManager;
55
        static::$config = $config;
56
    }
57
58
    public static function getServiceManager()
59
    {
60
        return static::$serviceManager;
61
    }
62
63
    public static function getConfig()
64
    {
65
        return static::$config;
66
    }
67
68
    protected static function initAutoloader()
69
    {
70
        $vendorPath = static::findParentPath('vendor');
71
72
        if (is_readable($vendorPath . '/autoload.php')) {
73
            $loader = include $vendorPath . '/autoload.php';
0 ignored issues
show
Unused Code introduced by
$loader is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
        } else {
75
            $zf2Path = getenv('ZF2_PATH') ?: (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath . '/ZF2/library') ? $vendorPath . '/ZF2/library' : false));
76
77
            if (!$zf2Path) {
78
                throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
79
            }
80
81
            include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
82
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
83
        }
84
85
        AutoloaderFactory::factory(array(
86
            'Zend\Loader\StandardAutoloader' => array(
87
                'autoregister_zf' => true,
88
                'namespaces' => array(
89
                    __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__,
90
                ),
91
            ),
92
        ));
93
    }
94
95
    protected static function findParentPath($path)
96
    {
97
        $dir = __DIR__;
98
        $previousDir = '.';
99
        while (!is_dir($dir . '/' . $path)) {
100
            $dir = dirname($dir);
101
            if ($previousDir === $dir) return false;
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
102
            $previousDir = $dir;
103
        }
104
        return $dir . '/' . $path;
105
    }
106
}
107
108
Bootstrap::init();