Completed
Pull Request — master (#93)
by Alessandro
02:47
created

SymfonyProcessWrapper::restart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Process;
5
6
use Symfony\Component\Process\Process;
7
8
/**
9
 * Class SymfonyProcessWrapper
10
 * @package Paraunit\Process
11
 */
12
class SymfonyProcessWrapper extends AbstractParaunitProcess
13
{
14
    /** @var Process */
15
    private $process;
16
17
    /**
18
     * SymfonyProcessWrapper constructor.
19
     * @param string $filePath
20
     * @param string $commandLine
21
     * @param string $uniqueId
22
     * @throws \InvalidArgumentException
23
     * @throws \Symfony\Component\Process\Exception\RuntimeException
24
     */
25 28
    public function __construct(string $filePath, string $commandLine, string $uniqueId)
26
    {
27 28
        parent::__construct($filePath, $uniqueId);
28 28
        $this->process = new Process($commandLine);
29
    }
30
31 16
    public function isTerminated(): bool
32
    {
33 16
        return $this->process->isTerminated();
34
    }
35
36
    /**
37
     * @return void
38
     * @throws \Symfony\Component\Process\Exception\LogicException
39
     * @throws \Symfony\Component\Process\Exception\RuntimeException
40
     */
41 16
    public function start()
42
    {
43 16
        $this->process->start();
44
    }
45
46
    /**
47
     * @return string
48
     * @throws \Symfony\Component\Process\Exception\LogicException
49
     */
50 5
    public function getOutput(): string
51
    {
52 5
        return $this->process->getOutput();
53
    }
54
55
    /**
56
     * @return int|null
57
     * @throws \Symfony\Component\Process\Exception\RuntimeException
58
     */
59 16
    public function getExitCode()
60
    {
61 16
        return $this->process->getExitCode();
62
    }
63
64
    /**
65
     * @return void
66
     * @throws \Symfony\Component\Process\Exception\RuntimeException
67
     * @throws \Symfony\Component\Process\Exception\LogicException
68
     */
69
    public function restart()
70
    {
71
        $this->reset();
72
        $this->start();
73
    }
74
75
    /**
76
     * @return void
77
     * @throws \Symfony\Component\Process\Exception\RuntimeException
78
     */
79 5
    public function reset()
80
    {
81 5
        parent::reset();
82
83 5
        $this->process = new Process($this->process->getCommandLine());
84
    }
85
86 1
    public function getCommandLine(): string
87
    {
88 1
        return $this->process->getCommandLine();
89
    }
90
91
    public function isRunning(): bool
92
    {
93
        return $this->process->isRunning();
94
    }
95
}
96