SymfonyProcessWrapper::getOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Process;
6
7
use Paraunit\Configuration\EnvVariables;
8
use Symfony\Component\Process\Process;
9
10
/**
11
 * Class SymfonyProcessWrapper
12
 * @package Paraunit\Process
13
 */
14
class SymfonyProcessWrapper extends AbstractParaunitProcess
15
{
16
    /** @var Process */
17
    private $process;
18
19
    /** @var string */
20
    protected $commandLine;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 28
    public function __construct(Process $process, string $filename)
26
    {
27 28
        parent::__construct($filename);
28 28
        $this->process = $process;
29
    }
30
31 24
    public function isTerminated(): bool
32
    {
33 24
        return $this->process->isTerminated();
34
    }
35
36
    /**
37
     * @param int $pipelineNumber
38
     */
39 25
    public function start(int $pipelineNumber)
40
    {
41 25
        $this->reset();
42 25
        $env = $this->process->getEnv();
43 25
        $env[EnvVariables::PROCESS_UNIQUE_ID] = $this->getUniqueId();
44 25
        $env[EnvVariables::PIPELINE_NUMBER] = $pipelineNumber;
45
46 25
        $this->process->setEnv($env);
47 25
        $this->process->start();
48
    }
49
50
    /**
51
     * @return string
52
     * @throws \Symfony\Component\Process\Exception\LogicException
53
     */
54 12
    public function getOutput(): string
55
    {
56 12
        return $this->process->getOutput() ?? '';
57
    }
58
59
    /**
60
     * @return int|null
61
     * @throws \Symfony\Component\Process\Exception\RuntimeException
62
     */
63 24
    public function getExitCode()
64
    {
65 24
        return $this->process->getExitCode();
66
    }
67
68
    /**
69
     * @return string
70
     */
71 2
    public function getCommandLine(): string
72
    {
73 2
        return $this->process->getCommandLine();
74
    }
75
}
76