Completed
Pull Request — master (#294)
by
unknown
02:21
created

Install::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
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
    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(6);
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 --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->progressBar->finish();
67
        $this->info(" Backpack\Base installation finished.");
68
    }
69
70
    /**
71
     * Run a SSH command.
72
     *
73
     * @param string $command      The SSH command that needs to be run
74
     * @param bool   $beforeNotice Information for the user before the command is run
75
     * @param bool   $afterNotice  Information for the user after the command is run
76
     *
77
     * @return mixed Command-line output
78
     */
79
    public function executeProcess($command, $beforeNotice = false, $afterNotice = false)
80
    {
81
        $this->echo('info', $beforeNotice ? ' '.$beforeNotice : $command);
82
83
        $process = new Process($command, null, null, null, $this->option('timeout'), null);
0 ignored issues
show
Documentation introduced by
$this->option('timeout') is of type string|array, but the function expects a integer.

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...
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...
84
        $process->run(function ($type, $buffer) {
85
            if (Process::ERR === $type) {
86
                $this->echo('comment', $buffer);
87
            } else {
88
                $this->echo('line', $buffer);
89
            }
90
        });
91
92
        // executes after the command finishes
93
        if (!$process->isSuccessful()) {
94
            throw new ProcessFailedException($process);
95
        }
96
97
        if ($this->progressBar) {
98
            $this->progressBar->advance();
99
        }
100
101
        if ($afterNotice) {
102
            $this->echo('info', $afterNotice);
103
        }
104
    }
105
106
    /**
107
     * Write text to the screen for the user to see.
108
     *
109
     * @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...
110
     * @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...
111
     */
112
    public function echo($type, $content)
113
    {
114
        if ($this->option('debug') == false) {
115
            return;
116
        }
117
118
        // skip empty lines
119
        if (trim($content)) {
120
            $this->{$type}($content);
121
        }
122
    }
123
}
124