Completed
Pull Request — master (#177)
by
unknown
04:33
created

N98_Magerun_Bootstrap::getLoader()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 3
eloc 7
nc 2
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 4 and the first side effect is on line 31.

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
3
if (!class_exists('N98_Magerun_Bootstrap')) {
4
    class N98_Magerun_Bootstrap
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
    {
6
        public static function includeIfExists($file)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
7
        {
8
            if (file_exists($file)) {
9
                return include $file;
10
            }
11
        }
12
13
        /**
14
         * @throws ErrorException
15
         * @return \Composer\Autoload\ClassLoader
16
         */
17
        public static function getLoader()
18
        {
19
            if ((!$loader = \N98_Magerun_Bootstrap::includeIfExists(__DIR__.'/../vendor/autoload.php'))
20
                && (!$loader = \N98_Magerun_Bootstrap::includeIfExists(__DIR__.'/../../../autoload.php'))) {
21
                throw new \ErrorException('You must set up the project dependencies, run the following commands:'.PHP_EOL.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
22
                    'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
23
                    'php composer.phar install'.PHP_EOL);
24
            }
25
26
            return $loader;
27
        }
28
    }
29
}
30
31
try {
32
    if (version_compare(PHP_VERSION, '5.4.11', '<')) {
33
        throw new \ErrorException('PHP Version is lower than 5.4.11. Please upgrade your runtime.');
34
    }
35
36
    $loader = \N98_Magerun_Bootstrap::getLoader();
37
    $application = new \N98\Magento\Application($loader);
38
39
    return $application;
40
41
} catch (\Exception $e) {
42
    echo $e->getMessage();
43
    exit(1);
44
}
45