Failed Conditions
Push — master ( 898d32...e0e3f0 )
by Sébastien
03:39
created

getSymfonyProcessRuntimeException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\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
    public function __construct(Process $process, SPException\RuntimeException $previousException)
16
    {
17
        if ($previousException instanceof SPException\ProcessFailedException ||
18
            $previousException instanceof SPException\ProcessTimedOutException ||
19
            $previousException instanceof SPException\ProcessSignaledException
20
        ) {
21
            $code = $previousException->getProcess()->getExitCode();
22
        } else {
23
            $code = 1;
24
        }
25
26
        parent::__construct(
27
            $previousException->getMessage(),
28
            $code,
29
            $previousException
30
        );
31
32
        $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...
33
    }
34
35
    /**
36
     * Return symfony process object.
37
     */
38
    public function getProcess(): Process
39
    {
40
        return $this->process;
41
    }
42
43
    public function geErrorOutput(): string
44
    {
45
        return $this->process->getErrorOutput();
46
    }
47
48
    /**
49
     * @return SPException\RuntimeException|SPException\ProcessFailedException|SPException\ProcessSignaledException|SPException\ProcessTimedOutException
50
     */
51
    public function getSymfonyProcessRuntimeException(): SPException\RuntimeException
52
    {
53
        /**
54
         * @var SPException\RuntimeException
55
         */
56
        $previous = $this->getPrevious();
57
58
        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...
59
    }
60
}
61