Completed
Pull Request — master (#183)
by Cristian
02:00
created

Install::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'backpack:base:install';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Require dev packages and publish files for Backpack\Base to work';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @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...
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function handle()
41
    {
42
        $this->info("### Backpack\Base installation started. Please wait...");
43
44
        $this->executeProcess('composer require backpack/generators --dev');
45
        $this->executeProcess('composer require laracasts/generators:dev-master --dev');
46
        $this->executeProcess("php artisan vendor:publish --provider='Backpack\Base\BaseServiceProvider'", 'publishing configs, langs, views and AdminLTE files');
0 ignored issues
show
Documentation introduced by
'publishing configs, lan...ews and AdminLTE files' is of type string, but the function expects a boolean.

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...
47
        $this->executeProcess("php artisan vendor:publish --provider='Prologue\Alerts\AlertsServiceProvider'", 'publishing config for notifications - prologue/alerts');
0 ignored issues
show
Documentation introduced by
'publishing config for n...ions - prologue/alerts' is of type string, but the function expects a boolean.

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...
48
        $this->executeProcess('php artisan migrate', "generating users table (using Laravel's default migrations)");
0 ignored issues
show
Documentation introduced by
'generating users table ...'s default migrations)' is of type string, but the function expects a boolean.

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...
49
50
        $this->info("### Backpack\Base installation finished.");
51
    }
52
53
    /**
54
     * Run a SSH command.
55
     *
56
     * @param string $command      The SSH command that needs to be run
57
     * @param bool   $beforeNotice Information for the user before the command is run
58
     * @param bool   $afterNotice  Information for the user after the command is run
59
     *
60
     * @return mixed Command-line output
61
     */
62
    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
63
    {
64
        if ($beforeNotice) {
65
            $this->info('### '.$beforeNotice);
66
        } else {
67
            $this->info('### Running: '.$command);
68
        }
69
70
        $process = new Process($command);
71
        $process->run(function ($type, $buffer) {
72
            if (Process::ERR === $type) {
73
                echo '... > '.$buffer;
74
            } else {
75
                echo 'OUT > '.$buffer;
76
            }
77
        });
78
79
        // executes after the command finishes
80
        if (!$process->isSuccessful()) {
81
            throw new ProcessFailedException($process);
82
        }
83
84
        if ($afterNotice) {
85
            $this->info('### '.$afterNotice);
86
        }
87
    }
88
}
89