ChurnProcess::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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