Completed
Push — master ( f0e6e1...5d896c )
by Carlos C
04:06 queued 02:35
created

ShellExec::exec()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\CfdiToPdf\Utils;
6
7
class ShellExec
8
{
9
    /** @var string */
10
    private $command;
11
12
    /** @var string[] */
13
    private $output;
14
15
    /** @var string */
16
    private $lastLine;
17
18
    /** @var int */
19
    private $exitStatus;
20
21
    /**
22
     * ShellExec constructor.
23
     * @param string $command
24
     * @param string[] $output
25
     * @param int $exitStatus
26
     * @param string $lastLine
27
     */
28 1
    public function __construct(string $command, array $output = [], int $exitStatus = -1, string $lastLine = '')
29
    {
30 1
        $this->command = $command;
31 1
        $this->output = $output;
32 1
        $this->exitStatus = $exitStatus;
33 1
        $this->lastLine = $lastLine;
34 1
    }
35
36 1
    public function command(): string
37
    {
38 1
        return $this->command;
39
    }
40
41 1
    public function output(): array
42
    {
43 1
        return $this->output;
44
    }
45
46
    public function lastLine(): string
47
    {
48
        return $this->lastLine;
49
    }
50
51 1
    public function exitStatus(): int
52
    {
53 1
        return $this->exitStatus;
54
    }
55
56 1
    public function exec()
57
    {
58 1
        $output = [];
59 1
        $exitStatus = -1;
60 1
        $lastline = exec($this->command(), $output, $exitStatus);
61
62 1
        $this->output = $output;
0 ignored issues
show
Documentation Bug introduced by
It seems like $output can be null. However, the property $output is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
63 1
        $this->exitStatus = $exitStatus;
64 1
        $this->lastLine = $lastline;
65 1
    }
66
67 1
    public static function run(string $command): self
68
    {
69 1
        $shellExec = new self($command);
70 1
        $shellExec->exec();
71 1
        return $shellExec;
72
    }
73
}
74