Issues (40)

app/Console/Commands/InstallCommand.php (2 issues)

1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
class InstallCommand extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'laravel-newsletter:install {--demo : Import demo data}';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Installation of the Laravel Newsletter application';
22
23
    /**
24
     * Create a new command instance.
25
     *
26
     * @return void
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return mixed
37
     */
38
    public function handle()
39
    {
40
        $this->info("\nWelcome to the installation process of Laravel Newsletter!\n");
41
42
        if (! $this->confirm('Do you like to continue with the installation of Laravel Newsletter?')) {
43
            $this->info("\nYou stopped the installation of Laravel Newsletter\n");
44
45
            return;
46
        }
47
48
        $this->install();
49
50
        if ($this->option('demo') || $this->confirm('Do you like to import the demo data?')) {
51
            $this->call('laravel-newsletter:demo');
52
        }
53
54
        $this->info("You've completed the installation process of Laravel Newsletter successfully!\n");
55
    }
56
57
    protected function install()
58
    {
59
        $this->line("\nInstalling..");
60
61
        if (! file_exists('.env')) {
62
            exec('mv .env.example .env');
63
            $this->line("\n.env file successfully created\n");
64
        }
65
66
        if (strlen(config('app.key')) === 0) {
0 ignored issues
show
The call to config() has too few arguments starting with default. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        if (strlen(/** @scrutinizer ignore-call */ config('app.key')) === 0) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
67
            $this->call('key:generate');
68
            $this->line("\nSecret key properly generated\n");
69
        }
70
71
        $dbEnv['DB_HOST'] = $this->ask('Database host');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$dbEnv was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dbEnv = array(); before regardless.
Loading history...
72
        $dbEnv['DB_DATABASE'] = $this->ask('Database name');
73
        $dbEnv['DB_USERNAME'] = $this->ask('Database user');
74
        $dbEnv['DB_PASSWORD'] = $this->secret('Database password ("null" for no password)');
75
        $this->updateEnvironmentFile($dbEnv);
76
77
        $this->line("Application installed.\n");
78
    }
79
80
    /**
81
     * Update .env file from an array of $key => $value pairs.
82
     *
83
     * @param array $updatedValues
84
     * @return void
85
     */
86
    protected function updateEnvironmentFile($updatedValues)
87
    {
88
        foreach ($updatedValues as $key => $value) {
89
            file_put_contents($this->laravel->environmentFilePath(), preg_replace(
90
                "/{$key}=(.*)/",
91
                $key.'='.$value,
92
                file_get_contents($this->laravel->environmentFilePath())
93
            ));
94
        }
95
    }
96
}
97