Passed
Push — master ( 963a97...4c1110 )
by Fabien
02:21
created

ChurnProcess::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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