Completed
Push — master ( 460b97...b63ecb )
by Ryan
05:27
created

InitializeApplication::handle()   C

Complexity

Conditions 9
Paths 16

Size

Total Lines 66
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 25
nc 16
nop 2
dl 0
loc 66
rs 6.4099
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace Anomaly\Streams\Platform\Application\Command;
2
3
use Anomaly\Streams\Platform\Application\Application;
4
use Illuminate\Contracts\Foundation\Application as Laravel;
5
use Symfony\Component\Console\Input\ArgvInput;
6
7
/**
8
 * Class InitializeApplication
9
 *
10
 * @link   http://pyrocms.com/
11
 * @author PyroCMS, Inc. <[email protected]>
12
 * @author Ryan Thompson <[email protected]>
13
 */
14
class InitializeApplication
15
{
16
17
    /**
18
     * Handle the command.
19
     *
20
     * @param Application $application
21
     */
22
    public function handle(Application $application, Laravel $laravel)
23
    {
24
        $app = env('APPLICATION_REFERENCE', 'default');
25
26
        if (PHP_SAPI == 'cli') {
27
            $app = (new ArgvInput())->getParameterOption('--app', $app);
28
29
            $laravel->bind(
30
                'path.public',
31
                function () use ($laravel) {
32
                    if ($path = env('PUBLIC_PATH')) {
33
                        return base_path($path);
34
                    }
35
36
                    // Check default path.
37
                    if (file_exists($path = base_path('public/index.php'))) {
38
                        return dirname($path);
39
                    }
40
41
                    // Check common alternative.
42
                    if (file_exists($path = base_path('public_html/index.php'))) {
43
                        return dirname($path);
44
                    }
45
46
                    return base_path('public');
47
                }
48
            );
49
        }
50
51
        /*
52
         * Set the reference to our default first.
53
         * When in a dev environment and working
54
         * with Artisan this the same as locating.
55
         */
56
        $application->setReference($app);
57
58
        /*
59
         * If the application is installed
60
         * then locate the application and
61
         * initialize.
62
         */
63
        if ($application->isInstalled()) {
64
65
            if (env('DB_CONNECTION', env('DB_DRIVER'))) {
66
67
                try {
68
                    $application->locate();
69
                    $application->setup();
70
71
                    if (!$application->isEnabled()) {
72
                        abort(503);
73
                    }
74
                } catch(\Exception $e) {
75
                    // Do nothing.
76
                }
77
            }
78
79
            return;
80
        }
81
82
        /*
83
         * If we're not installed just
84
         * assume default for now.
85
         */
86
        $application->setReference('default');
87
    }
88
}
89