Completed
Pull Request — master (#300)
by Cristian
04:30 queued 02:08
created

Version::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
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 Version extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'backpack:base:version';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Show the version of PHP and Backpack packages.';
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->comment('### PHP VERSION:');
43
        $this->runCommand('php -v');
44
45
        $this->comment('### BACKPACK PACKAGES VERSION:');
46
        $this->runCommand('composer show | grep "backpack\|laravel/framework"');
47
48
        $this->comment('### MYSQL VERSION:');
49
        $this->runCommand('mysql --version');
50
    }
51
52
    /**
53
     * Run a shell command in a separate process.
54
     *
55
     * @param string $command Text to be executed.
56
     *
57
     * @return void
58
     */
59
    private function runCommand($command)
60
    {
61
        $process = new Process($command, null, null, null, 60, 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...
62
        $process->run(function ($type, $buffer) {
63
            if (Process::ERR === $type) {
64
                $this->line($buffer);
65
            } else {
66
                $this->line($buffer);
67
            }
68
        });
69
70
        // executes after the command finishes
71
        if (!$process->isSuccessful()) {
72
            throw new ProcessFailedException($process);
73
        }
74
    }
75
}
76