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

SymfonyProcessWrapper   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 76.19%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 84
ccs 16
cts 21
cp 0.7619
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isRunning() 0 4 1
A __construct() 0 5 1
A isTerminated() 0 4 1
A start() 0 4 1
A getOutput() 0 4 1
A getExitCode() 0 4 1
A restart() 0 5 1
A reset() 0 6 1
A getCommandLine() 0 4 1
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