Install   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 5
dl 0
loc 121
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 31 1
B executeProcess() 0 26 6
A echo() 0 11 3
1
<?php
2
3
namespace Backpack\Base\app\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Process\Exception\ProcessFailedException;
7
use Symfony\Component\Process\Process;
8
9
class Install extends Command
10
{
11
    protected $progressBar;
12
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'backpack:base:install
19
                                {--timeout=300} : How many seconds to allow each process to run.
20
                                {--debug} : Show process output or not. Useful for debugging.';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Require dev packages and publish files for Backpack\Base to work';
28
29
    /**
30
     * Create a new command instance.
31
     *
32
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
33
     */
34
    public function __construct()
35
    {
36
        parent::__construct();
37
    }
38
39
    /**
40
     * Execute the console command.
41
     *
42
     * @return mixed
43
     */
44
    public function handle()
45
    {
46
        $this->progressBar = $this->output->createProgressBar(8);
47
        $this->progressBar->start();
48
        $this->info(" Backpack\Base installation started. Please wait...");
49
        $this->progressBar->advance();
50
51
        $this->line(' Installing backpack/generators');
52
        $this->executeProcess('composer require backpack/generators:"1.2.*" --dev');
53
54
        $this->line(' Installing laracasts/generators');
55
        $this->executeProcess('composer require laracasts/generators:dev-master --dev');
56
57
        $this->line(' Publishing configs, langs, views and AdminLTE files');
58
        $this->executeProcess('php artisan vendor:publish --provider="Backpack\Base\BaseServiceProvider" --tag=minimum');
59
60
        $this->line(' Publishing config for notifications - prologue/alerts');
61
        $this->executeProcess('php artisan vendor:publish --provider="Prologue\Alerts\AlertsServiceProvider"');
62
63
        $this->line(" Generating users table (using Laravel's default migrations)");
64
        $this->executeProcess('php artisan migrate');
65
66
        $this->line(" Creating App\Models\BackpackUser.php");
67
        $this->executeProcess('php artisan backpack:base:publish-user-model');
68
69
        $this->line(" Creating App\Http\Middleware\CheckIfAdmin.php");
70
        $this->executeProcess('php artisan backpack:base:publish-middleware');
71
72
        $this->progressBar->finish();
73
        $this->info(" Backpack\Base installation finished.");
74
    }
75
76
    /**
77
     * Run a SSH command.
78
     *
79
     * @param string $command      The SSH command that needs to be run
80
     * @param bool   $beforeNotice Information for the user before the command is run
81
     * @param bool   $afterNotice  Information for the user after the command is run
82
     *
83
     * @return mixed Command-line output
84
     */
85
    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
86
    {
87
        $this->echo('info', $beforeNotice ? ' '.$beforeNotice : $command);
88
89
        $process = new Process($command, null, null, null, $this->option('timeout'), null);
0 ignored issues
show
Unused Code introduced by
The call to Process::__construct() has too many arguments starting with null.

This check compares calls to functions or methods with their respective definitions. If the call has more 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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Documentation introduced by
$command is of type string, but the function expects a array.

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
        $process->run(function ($type, $buffer) {
91
            if (Process::ERR === $type) {
92
                $this->echo('comment', $buffer);
93
            } else {
94
                $this->echo('line', $buffer);
95
            }
96
        });
97
98
        // executes after the command finishes
99
        if (!$process->isSuccessful()) {
100
            throw new ProcessFailedException($process);
101
        }
102
103
        if ($this->progressBar) {
104
            $this->progressBar->advance();
105
        }
106
107
        if ($afterNotice) {
108
            $this->echo('info', $afterNotice);
109
        }
110
    }
111
112
    /**
113
     * Write text to the screen for the user to see.
114
     *
115
     * @param [string] $type    line, info, comment, question, error
0 ignored issues
show
Documentation introduced by
The doc-type [string] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
116
     * @param [string] $content
0 ignored issues
show
Documentation introduced by
The doc-type [string] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
117
     */
118
    public function echo($type, $content)
119
    {
120
        if ($this->option('debug') == false) {
121
            return;
122
        }
123
124
        // skip empty lines
125
        if (trim($content)) {
126
            $this->{$type}($content);
127
        }
128
    }
129
}
130