Failed Conditions
Push — master ( bdd819...56a037 )
by Sébastien
02:43
created

src/Exception/ProcessConversionException.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Exception;
6
7
use Symfony\Component\Process\Exception as SymfonyProcessException;
8
use Symfony\Component\Process\Process;
9
10
class ProcessConversionException extends RuntimeException implements ProcessExceptionInterface
11
{
12
    /** @var Process */
13
    private $process;
14
15
    public function __construct(Process $process, SymfonyProcessException\RuntimeException $previousException)
16
    {
17
        parent::__construct(
18
            $previousException->getMessage(),
19
            $previousException->getCode(),
20
            $previousException
21
        );
22
23
        $this->process = $process;
24
    }
25
26
    /**
27
     * Return symfony process object.
28
     */
29
    public function getProcess(): Process
30
    {
31
        return $this->process;
32
    }
33
34
    public function wasCausedByFailure(): bool
35
    {
36
        return $this->getPrevious() instanceof SymfonyProcessException\ProcessFailedException;
37
    }
38
39
    public function wasCausedBySignal(): bool
40
    {
41
        return $this->getPrevious() instanceof SymfonyProcessException\ProcessSignaledException;
42
    }
43
44
    public function wasCausedByTimeout(): bool
45
    {
46
        return $this->getPrevious() instanceof SymfonyProcessException\ProcessTimedOutException;
47
    }
48
49
    /**
50
     * @return SymfonyProcessException\ProcessFailedException|SymfonyProcessException\ProcessSignaledException|SymfonyProcessException\ProcessTimedOutException
51
     */
52
    public function getSymfonyProcessRuntimeException(): SymfonyProcessException\RuntimeException
53
    {
54
        /**
55
         * @var \Symfony\Component\Process\Exception\RuntimeException
56
         */
57
        $previous = $this->getPrevious();
58
59
        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...
60
    }
61
}
62