Symfony::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 12
cts 12
cp 1
rs 9.584
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * This file is part of SebastianFeldmann\Cli.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace SebastianFeldmann\Cli\Processor;
13
14
use SebastianFeldmann\Cli\Command\Result;
15
use SebastianFeldmann\Cli\Processor;
16
use Symfony\Component\Process\Process;
17
18
/**
19
 * Class ProcOpen
20
 *
21
 * @package SebastianFeldmann\Cli
22
 * @author  Sebastian Feldmann <[email protected]>
23
 * @link    https://github.com/sebastianfeldmann/cli
24
 * @since   Class available since Release 3.2.2
25
 */
26
class Symfony implements Processor
27
{
28
    /**
29
     * Execute the command
30
     *
31
     * @param  string $cmd
32
     * @param  int[]  $acceptableExitCodes
33
     * @return \SebastianFeldmann\Cli\Command\Result
34 3
     */
35
    public function run(string $cmd, array $acceptableExitCodes = [0]): Result
36 3
    {
37 3
        // the else (:) variant is there to keep backwards compatibility with previous symfony versions
38 3
        // and is only getting executed in those. This is the reason why the Process constructor is
39
        // given a string instead of an array. The whole ternary can be removed if Symfony versions
40 3
        // below 4.2 are not supported anymore.
41 3
        $process = method_exists(Process::class, 'fromShellCommandline')
42 3
                 ? Process::fromShellCommandline($cmd)
43 3
                 : new Process($cmd); // @phpstan-ignore-line
0 ignored issues
show
Documentation introduced by
$cmd 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...
44 3
45 3
        $process->setTimeout(null);
46 3
        $process->run();
47 3
        return new Result(
48 3
            $cmd,
49
            $process->getExitCode(),
50
            $process->getOutput(),
51
            $process->getErrorOutput(),
52
            '',
53
            $acceptableExitCodes
54
        );
55
    }
56
}
57