RemoteProcessFailedException::getProcess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Assimtech\Tempo\Process\Exception;
4
5
use Symfony\Component\Process\Exception\RuntimeException;
6
use Symfony\Component\Process\Process;
7
use InvalidArgumentException;
8
9
class RemoteProcessFailedException extends RuntimeException
10
{
11
    private $process;
12
13
    public function __construct(Process $process)
14
    {
15
        if ($process->isSuccessful()) {
16
            throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
17
        }
18
19
        $error = sprintf('The command "%s" failed.', $process->getInput());
20
21
        if (!$process->isOutputDisabled()) {
22
            $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
23
                $process->getOutput(),
24
                $process->getErrorOutput()
25
            );
26
        }
27
28
        parent::__construct($error);
29
30
        $this->process = $process;
31
    }
32
33
    public function getProcess()
34
    {
35
        return $this->process;
36
    }
37
}
38