Install::fire()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 53
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 33
nc 2
nop 2
dl 0
loc 53
rs 9.5797
c 2
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\Installer\Console;
2
3
use Anomaly\Streams\Platform\Addon\AddonManager;
4
use Anomaly\Streams\Platform\Application\Command\InitializeApplication;
5
use Anomaly\Streams\Platform\Application\Command\LoadEnvironmentOverrides;
6
use Anomaly\Streams\Platform\Application\Command\ReloadEnvironmentFile;
7
use Anomaly\Streams\Platform\Application\Command\WriteEnvironmentFile;
8
use Anomaly\Streams\Platform\Entry\Command\AutoloadEntryModels;
9
use Anomaly\Streams\Platform\Installer\Console\Command\ConfigureDatabase;
10
use Anomaly\Streams\Platform\Installer\Console\Command\ConfirmLicense;
11
use Anomaly\Streams\Platform\Installer\Console\Command\LoadApplicationInstallers;
12
use Anomaly\Streams\Platform\Installer\Console\Command\LoadBaseMigrations;
13
use Anomaly\Streams\Platform\Installer\Console\Command\LoadBaseSeeders;
14
use Anomaly\Streams\Platform\Installer\Console\Command\LoadCoreInstallers;
15
use Anomaly\Streams\Platform\Installer\Console\Command\LoadExtensionInstallers;
16
use Anomaly\Streams\Platform\Installer\Console\Command\LoadExtensionSeeders;
17
use Anomaly\Streams\Platform\Installer\Console\Command\LoadModuleInstallers;
18
use Anomaly\Streams\Platform\Installer\Console\Command\LoadModuleSeeders;
19
use Anomaly\Streams\Platform\Installer\Console\Command\RunInstallers;
20
use Anomaly\Streams\Platform\Installer\Console\Command\SetAdminData;
21
use Anomaly\Streams\Platform\Installer\Console\Command\SetApplicationData;
22
use Anomaly\Streams\Platform\Installer\Console\Command\SetDatabaseData;
23
use Anomaly\Streams\Platform\Installer\Console\Command\SetDatabasePrefix;
24
use Anomaly\Streams\Platform\Installer\Console\Command\SetOtherData;
25
use Anomaly\Streams\Platform\Installer\Console\Command\SetStreamsData;
26
use Anomaly\Streams\Platform\Installer\Installer;
27
use Anomaly\Streams\Platform\Installer\InstallerCollection;
28
use Anomaly\Streams\Platform\Support\Collection;
29
use Illuminate\Console\Command;
30
use Illuminate\Contracts\Events\Dispatcher;
31
use Illuminate\Foundation\Bus\DispatchesJobs;
32
use Symfony\Component\Console\Input\InputOption;
33
34
/**
35
 * Class Install
36
 *
37
 * @link   http://pyrocms.com/
38
 * @author PyroCMS, Inc. <[email protected]>
39
 * @author Ryan Thompson <[email protected]>
40
 */
41
class Install extends Command
42
{
43
44
    use DispatchesJobs;
45
46
    /**
47
     * The console command name.
48
     *
49
     * @var string
50
     */
51
    protected $name = 'install';
52
53
    /**
54
     * The console command description.
55
     *
56
     * @var string
57
     */
58
    protected $description = 'Install the Streams Platform.';
59
60
    /**
61
     * Execute the console command.
62
     *
63
     * @param Dispatcher   $events
64
     * @param AddonManager $manager
65
     */
66
    public function fire(Dispatcher $events, AddonManager $manager)
67
    {
68
        $data = new Collection();
69
70
        if (!$this->option('ready')) {
71
72
            $this->dispatch(new ConfirmLicense($this));
73
            $this->dispatch(new SetStreamsData($data));
74
            $this->dispatch(new SetDatabaseData($data, $this));
75
            $this->dispatch(new SetApplicationData($data, $this));
76
            $this->dispatch(new SetAdminData($data, $this));
77
            $this->dispatch(new SetOtherData($data, $this));
78
79
            $this->dispatch(new WriteEnvironmentFile($data->all()));
80
        }
81
82
        $this->dispatch(new ReloadEnvironmentFile());
83
        $this->dispatch(new LoadEnvironmentOverrides());
84
        $this->dispatch(new InitializeApplication());
85
86
        $this->dispatch(new ConfigureDatabase());
87
        $this->dispatch(new SetDatabasePrefix());
88
89
        $installers = new InstallerCollection();
90
91
        $this->dispatch(new LoadCoreInstallers($installers));
92
        $this->dispatch(new LoadApplicationInstallers($installers));
93
        $this->dispatch(new LoadModuleInstallers($installers));
94
        $this->dispatch(new LoadExtensionInstallers($installers));
95
96
        $installers->add(
97
            new Installer(
98
                'streams::installer.reloading_application',
99
                function () use ($manager, $events) {
100
101
                    $this->call('env:set', ['line' => 'INSTALLED=true']);
102
103
                    $this->dispatch(new ReloadEnvironmentFile());
104
                    $this->dispatch(new AutoloadEntryModels()); // Don't forget!
105
106
                    $manager->register(); // Register all of our addons.
107
                }
108
            )
109
        );
110
111
        $this->dispatch(new LoadBaseMigrations($installers));
112
        $this->dispatch(new LoadBaseSeeders($installers));
113
114
        $this->dispatch(new LoadModuleSeeders($installers));
115
        $this->dispatch(new LoadExtensionSeeders($installers));
116
117
        $this->dispatch(new RunInstallers($installers, $this));
118
    }
119
120
    /**
121
     * Get the console command options.
122
     *
123
     * @return array
124
     */
125
    protected function getOptions()
126
    {
127
        return [
128
            ['ready', null, InputOption::VALUE_NONE, 'Indicates that the installer should use an existing .env file.'],
129
        ];
130
    }
131
}
132