Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 1b76b0...423952 )
by Cristian
08:09
created

Install::executeArtisanProcess()   A

Complexity

Conditions 5
Paths 10

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 10
nop 4
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Process\Exception\ProcessFailedException;
7
use Symfony\Component\Process\Process;
8
use Artisan;
9
10
class Install extends Command
11
{
12
    protected $progressBar;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'backpack:install
20
                                {--elfinder=ask : Should it install the File Manager. }
21
                                {--timeout=300} : How many seconds to allow each process to run.
22
                                {--debug} : Show process output or not. Useful for debugging.';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Install Backpack requirements on dev, publish files and create uploads directory.';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @return mixed Command-line output
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use false|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
35
     */
36
    public function handle()
37
    {
38
        /*
39
        * "ask" comes by default, when no option is provided, like: "backpack:install"
40
        * https://laravel.com/docs/6.0/artisan#options
41
        */
42
        $shouldInstallElfinder = false;
0 ignored issues
show
Unused Code introduced by
$shouldInstallElfinder 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...
43
44
        if ($this->option('elfinder') == 'ask') {
45
            $shouldInstallElfinder = $this->confirm('Install barryvdh/laravel-elfinder to provide an admin interface for File Management?', false);
46
        } elseif ($this->option('elfinder') == 'no') {
47
            $shouldInstallElfinder = false;
48
        } elseif ($this->option('elfinder') == 'yes') {
49
            $shouldInstallElfinder = true;
50
        } else {
51
            $this->error('Option not recognized: '.$this->option('elfinder'));
52
53
            return false;
54
        }
55
56
        $this->progressBar = $this->output->createProgressBar($shouldInstallElfinder ? 11 : 6);
57
        $this->progressBar->minSecondsBetweenRedraws(0);
58
        $this->progressBar->maxSecondsBetweenRedraws(120);
59
        $this->progressBar->setRedrawFrequency(1);
60
61
        $this->progressBar->start();
62
63
        $this->info(' Backpack installation started. Please wait...');
64
        $this->progressBar->advance();
65
66
        $this->line(' Publishing configs, langs, views, js and css files');
67
        $this->executeArtisanProcess('vendor:publish', [
68
                '--provider' => 'Backpack\CRUD\BackpackServiceProvider', 
69
                '--tag' => 'minimum'
70
        ]);
71
72
        $this->line(' Publishing config for notifications - prologue/alerts');
73
        $this->executeArtisanProcess('vendor:publish', [
74
            '--provider' => 'Prologue\Alerts\AlertsServiceProvider'
75
        ]);
76
77
        $this->line(" Generating users table (using Laravel's default migrations)");
78
        $this->executeArtisanProcess('migrate');
79
80
        $this->line(" Creating App\Models\BackpackUser.php");
81
        $this->executeArtisanProcess('backpack:publish-user-model');
82
83
        $this->line(" Creating App\Http\Middleware\CheckIfAdmin.php");
84
        $this->executeArtisanProcess('backpack:publish-middleware');
85
86
        // elFinder steps
87
        if ($shouldInstallElfinder) {
88
            $this->line(' Installing barryvdh/laravel-elfinder');
89
            $this->executeProcess(['composer', 'require', 'barryvdh/laravel-elfinder']);
0 ignored issues
show
Documentation introduced by
array('composer', 'requi...yvdh/laravel-elfinder') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
91
            $this->line(' Creating uploads directory');
92
            switch (DIRECTORY_SEPARATOR) {
93
                case '/': // unix
94
                    $createUploadDirectoryCommand = ['mkdir', '-p', 'public/uploads'];
95
                    break;
96
                case '\\': // windows
97
                    if (! file_exists('public\uploads')) {
98
                        $createUploadDirectoryCommand = ['mkdir', 'public\uploads'];
99
                    }
100
                    break;
101
            }
102
            if (isset($createUploadDirectoryCommand)) {
103
                $this->executeProcess($createUploadDirectoryCommand);
0 ignored issues
show
Documentation introduced by
$createUploadDirectoryCommand is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
104
            }
105
106
            $this->line(' Publishing elFinder assets');
107
            $this->executeArtisanProcess('elfinder:publish');
108
109
            $this->line(' Publishing custom elfinder views');
110
            $this->executeArtisanProcess('vendor:publish', [
111
                '--provider' => 'Backpack\CRUD\BackpackServiceProvider', 
112
                '--tag' => 'elfinder'
113
            ]);
114
115
            $this->line(' Adding sidebar menu item for File Manager');
116
            switch (DIRECTORY_SEPARATOR) {
117
                case '/': // unix
118
                    $this->executeArtisanProcess('backpack:add-sidebar-content', [ 
119
                        'code' => '<li class="nav-item"><a class="nav-link" href="{{ backpack_url(\'elfinder\') }}\"><i class="nav-icon fa fa-files-o"></i> <span>{{ trans(\'backpack::crud.file_manager\') }}</span></a></li>']);
120
                    break;
121
                case '\\': // windows
122
                    $this->executeArtisanProcess('backpack:add-sidebar-content', [
123
                        'code' => '<li class="nav-item"><a class="nav-link" href=""{{ backpack_url(\'elfinder\') }}""><i class=""nav-icon fa fa-files-o""></i> <span>{{ trans(\'backpack::crud.file_manager\') }}</span></a></li>']);
124
                    break;
125
            }
126
        }
127
        // end of elFinder steps
128
129
        $this->progressBar->finish();
130
        $this->info(' Backpack installation finished.');
131
    }
132
133
    /**
134
     * Run a SSH command.
135
     *
136
     * @param string $command      The SSH command that needs to be run
137
     * @param bool   $beforeNotice Information for the user before the command is run
138
     * @param bool   $afterNotice  Information for the user after the command is run
139
     *
140
     * @return mixed Command-line output
141
     */
142
    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
143
    {
144
        $this->echo('info', $beforeNotice ? ' '.$beforeNotice : $command);
145
146
        // make sure the command is an array as per Symphony 4.3+ requirement
147
        $command = is_string($command) ? explode(' ', $command) : $command;
148
149
        $process = new Process($command, null, null, null, $this->option('timeout'));
150
        $process->run(function ($type, $buffer) {
151
            if (Process::ERR === $type) {
152
                $this->echo('comment', $buffer);
153
            } else {
154
                $this->echo('line', $buffer);
155
            }
156
        });
157
158
        // executes after the command finishes
159
        if (! $process->isSuccessful()) {
160
            throw new ProcessFailedException($process);
161
        }
162
163
        if ($this->progressBar) {
164
            $this->progressBar->advance();
165
        }
166
167
        if ($afterNotice) {
168
            $this->echo('info', $afterNotice);
0 ignored issues
show
Documentation introduced by
$afterNotice is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
169
        }
170
    }
171
172
    /**
173
     * Run an artisan command.
174
     * 
175
     * @param  string  $command      The artisan command to be run.
176
     * @param  array   $arguments    Key-value array of arguments to the artisan command.
177
     * @param  bool    $beforeNotice Information for the user before the command is run
178
     * @param  bool    $afterNotice  Information for the user after the command is run
179
     *
180
     * @return mixed Command-line output
181
     */
182
    public function executeArtisanProcess($command, $arguments = [], $beforeNotice = false, $afterNotice = false)
183
    {
184
        $beforeNotice = $beforeNotice ? ' '.$beforeNotice : 'php artisan '.$command.' '.implode(' ', $arguments);
185
186
        $this->echo('info', $beforeNotice);
187
 
188
        try {
189
            Artisan::call($command, $arguments);
190
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Backpack\CRUD\app\Console\Commands\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
191
            throw new ProcessFailedException($e);
192
        }
193
194
        if ($this->progressBar) {
195
            $this->progressBar->advance();
196
        }
197
198
        if ($afterNotice) {
199
            $this->echo('info', $afterNotice);
0 ignored issues
show
Documentation introduced by
$afterNotice is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
200
        }
201
    }
202
203
    /**
204
     * Write text to the screen for the user to see.
205
     *
206
     * @param string $type    line, info, comment, question, error
207
     * @param string $content
208
     */
209
    public function echo($type, $content)
210
    {
211
        if ($this->option('debug') == false) {
212
            return;
213
        }
214
215
        // skip empty lines
216
        if (trim($content)) {
217
            $this->{$type}($content);
218
        }
219
    }
220
}
221