Passed
Pull Request — master (#301)
by Fabien
02:07
created

ChurnProcess::isSuccessful()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Process;
6
7
use Churn\File\File;
8
use Symfony\Component\Process\Exception\ProcessFailedException;
9
use Symfony\Component\Process\Process;
10
11
abstract class ChurnProcess
12
{
13
14
    /**
15
     * The file the process will be executed on.
16
     *
17
     * @var File
18
     */
19
    protected $file;
20
21
    /**
22
     * The Symfony Process Component.
23
     *
24
     * @var Process
25
     */
26
    protected $process;
27
28
    /**
29
     * Class constructor.
30
     *
31
     * @param File $file The file the process is being executed on.
32
     * @param Process $process The process being executed on the file.
33
     */
34
    public function __construct(File $file, Process $process)
35
    {
36
        $this->file = $file;
37
        $this->process = $process;
38
    }
39
40
    /**
41
     * Start the process.
42
     */
43
    public function start(): void
44
    {
45
        $this->process->start();
46
    }
47
48
    /**
49
     * Determines if the process was successful.
50
     *
51
     * @throws ProcessFailedException If the process failed.
52
     */
53
    public function isSuccessful(): bool
54
    {
55
        $exitCode = $this->process->getExitCode();
56
57
        if ($exitCode > 0) {
58
            throw new ProcessFailedException($this->process);
59
        }
60
61
        return 0 === $exitCode;
62
    }
63
64
    /**
65
     * Gets the file the process is being executed on.
66
     */
67
    public function getFile(): File
68
    {
69
        return $this->file;
70
    }
71
72
    /**
73
     * Gets the output of the process.
74
     */
75
    protected function getOutput(): string
76
    {
77
        return $this->process->getOutput();
78
    }
79
}
80