Completed
Push — master ( f72769...eb1d3e )
by Sébastien
08:28 queued 06:05
created

getSymfonyProcessRuntimeException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2019 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Common\Exception;
13
14
use Symfony\Component\Process\Exception as SPException;
15
use Symfony\Component\Process\Process;
16
17
class ProcessException extends RuntimeException implements ProcessExceptionInterface
18
{
19
    /** @var Process */
20
    protected $process;
21
22
    /**
23
     * @param string|null $message if not set will use the previousException message
24
     */
25 17
    public function __construct(Process $process, SPException\RuntimeException $previousException, ?string $message = null)
26
    {
27 17
        if ($previousException instanceof SPException\ProcessFailedException ||
28 1
            $previousException instanceof SPException\ProcessTimedOutException ||
29 17
            $previousException instanceof SPException\ProcessSignaledException
30
        ) {
31 17
            $code = $previousException->getProcess()->getExitCode();
32
        } else {
33
            $code = 1;
34
        }
35
36 17
        $msg = $message ?? $previousException->getMessage();
37
38 17
        parent::__construct(
39 17
            $msg,
40 17
            $code ?? 1,
41 17
            $previousException
42
        );
43
44 17
        $this->process = $process;
45 17
    }
46
47
    /**
48
     * Return symfony process object.
49
     */
50 1
    public function getProcess(): Process
51
    {
52 1
        return $this->process;
53
    }
54
55 1
    public function getErrorOutput(): string
56
    {
57 1
        return $this->process->getErrorOutput();
58
    }
59
60
    /**
61
     * @return SPException\RuntimeException|SPException\ProcessFailedException|SPException\ProcessSignaledException|SPException\ProcessTimedOutException
62
     */
63 1
    public function getSymfonyProcessRuntimeException(): SPException\RuntimeException
64
    {
65
        /**
66
         * @var SPException\RuntimeException $previous
67
         */
68 1
        $previous = $this->getPrevious();
69
70 1
        return $previous;
71
    }
72
}
73