Passed
Push — master ( b97c32...e7e450 )
by Carlos C
10:36 queued 12s
created

ShellExec::output()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Utils;
6
7
class ShellExec
8
{
9
    /** @param string[] $output */
10 4
    public function __construct(
11
        private string $command,
12
        private array $output = [],
13
        private int $exitStatus = -1,
14
        private string $lastLine = ''
15
    ) {
16
    }
17
18 4
    public function command(): string
19
    {
20 4
        return $this->command;
21
    }
22
23
    /** @return string[] */
24
    public function output(): array
25
    {
26
        return $this->output;
27
    }
28
29
    public function lastLine(): string
30
    {
31
        return $this->lastLine;
32
    }
33
34 4
    public function exitStatus(): int
35
    {
36 4
        return $this->exitStatus;
37
    }
38
39 4
    public function exec(): void
40
    {
41 4
        $output = [];
42 4
        $exitStatus = -1;
43
44 4
        $lastline = (string) exec($this->command(), $output, $exitStatus);
45
46 4
        $this->output = $output;
47 4
        $this->exitStatus = $exitStatus;
48 4
        $this->lastLine = $lastline;
49
    }
50
51 4
    public static function run(string $command): self
52
    {
53 4
        $shellExec = new self($command);
54 4
        $shellExec->exec();
55 4
        return $shellExec;
56
    }
57
}
58