Passed
Push — master ( a6a132...f48b58 )
by Pascal
03:05
created

EncodingException::decorate()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 1
nop 1
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\Exporters;
4
5
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
6
use FFMpeg\Exception\RuntimeException;
7
8
class EncodingException extends RuntimeException
9
{
10
    public static function decorate(RuntimeException $runtimeException): EncodingException
11
    {
12
        return tap(new static(
13
            $runtimeException->getMessage(),
14
            $runtimeException->getCode(),
15
            $runtimeException->getPrevious()
16
        ), function (self $exception) {
17
            if (config('laravel-ffmpeg.set_command_and_error_output_on_exception')) {
18
                $exception->message = $exception->getAlchemyException()->getMessage();
19
            }
20
        });
21
    }
22
23
    public function getCommand(): string
24
    {
25
        return $this->getAlchemyException()->getCommand();
26
    }
27
28
    public function getErrorOutput(): string
29
    {
30
        return $this->getAlchemyException()->getErrorOutput();
31
    }
32
33
    public function getAlchemyException(): ExecutionFailureException
34
    {
35
        return $this->getPrevious();
36
    }
37
}
38