Version   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 1
A runConsoleCommand() 0 16 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 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
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30
    public function handle()
31
    {
32
        $this->comment('### PHP VERSION:');
33
        $this->runConsoleCommand('php -v');
34
35
        $this->comment('### BACKPACK PACKAGES VERSION:');
36
        $this->runConsoleCommand('composer show | grep "backpack\|laravel/framework"');
37
38
        $this->comment('### MYSQL VERSION:');
39
        $this->runConsoleCommand('mysql --version');
40
    }
41
42
    /**
43
     * Run a shell command in a separate process.
44
     *
45
     * @param string $command Text to be executed.
46
     *
47
     * @return void
48
     */
49
    private function runConsoleCommand($command)
50
    {
51
        $process = new Process($command, null, null, null, 60, null);
0 ignored issues
show
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...
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...
52
        $process->run(function ($type, $buffer) {
53
            if (Process::ERR === $type) {
54
                $this->line($buffer);
55
            } else {
56
                $this->line($buffer);
57
            }
58
        });
59
60
        // executes after the command finishes
61
        if (!$process->isSuccessful()) {
62
            throw new ProcessFailedException($process);
63
        }
64
    }
65
}
66