Passed
Push — master ( e85209...2faa2d )
by Sébastien
03:53
created

ProcessException::getErrorOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Common\Exception;
6
7
use Symfony\Component\Process\Exception as SPException;
8
use Symfony\Component\Process\Process;
9
10
class ProcessException extends RuntimeException implements ProcessExceptionInterface
11
{
12
    /** @var Process */
13
    protected $process;
14
15
    /**
16
     * ProcessException constructor.
17
     *
18
     * @param Process                      $process
19
     * @param SPException\RuntimeException $previousException
20
     * @param string|null                  $message           if not set will use the previousException message
21
     */
22 10
    public function __construct(Process $process, SPException\RuntimeException $previousException, string $message = null)
23
    {
24 10
        if ($previousException instanceof SPException\ProcessFailedException ||
25 5
            $previousException instanceof SPException\ProcessTimedOutException ||
26 10
            $previousException instanceof SPException\ProcessSignaledException
27
        ) {
28 10
            $code = $previousException->getProcess()->getExitCode();
29
        } else {
30
            $code = 1;
31
        }
32
33 10
        $msg = $message ?? $previousException->getMessage();
34
35 10
        parent::__construct(
36 10
            $msg,
37 10
            $code ?? 1,
38 10
            $previousException
39
        );
40
41 10
        $this->process     = $process;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 5 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
42 10
    }
43
44
    /**
45
     * Return symfony process object.
46
     */
47 1
    public function getProcess(): Process
48
    {
49 1
        return $this->process;
50
    }
51
52 1
    public function getErrorOutput(): string
53
    {
54 1
        return $this->process->getErrorOutput();
55
    }
56
57
    /**
58
     * @return SPException\RuntimeException|SPException\ProcessFailedException|SPException\ProcessSignaledException|SPException\ProcessTimedOutException
59
     */
60 1
    public function getSymfonyProcessRuntimeException(): SPException\RuntimeException
61
    {
62
        /**
63
         * @var SPException\RuntimeException
64
         */
65 1
        $previous = $this->getPrevious();
66
67 1
        return $previous;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $previous returns the type Exception which includes types incompatible with the type-hinted return Symfony\Component\Proces...eption\RuntimeException.
Loading history...
68
    }
69
}
70