PipelineTaskFailedException::rejected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Zurbaev\PipelineTasks\Exceptions;
4
5
class PipelineTaskFailedException extends \RuntimeException
6
{
7
    const EXCEPTION_THROWN = 100;
8
    const REJECTED = 101;
9
10
    /**
11
     * Failed pipe name.
12
     *
13
     * @var string
14
     */
15
    protected $pipeName;
16
17
    /**
18
     * PipelineTaskFailed constructor.
19
     *
20
     * @param string          $pipeName
21
     * @param string          $message
22
     * @param int             $code
23
     * @param \Throwable|null $previous
24
     */
25
    public function __construct(string $pipeName, $message = '', $code = 0, \Throwable $previous = null)
26
    {
27
        parent::__construct($message, $code, $previous);
28
29
        $this->pipeName = $pipeName;
30
    }
31
32
    /**
33
     * Get the failed pipe name.
34
     *
35
     * @return string
36
     */
37
    public function getPipeName()
38
    {
39
        return $this->pipeName;
40
    }
41
42
    /**
43
     * Create new exception instance with EXCEPTION_THROWN status.
44
     *
45
     * @param string     $name
46
     * @param \Exception $e
47
     *
48
     * @return static
49
     */
50
    public static function exceptionThrown(string $name, \Exception $e)
51
    {
52
        return new static(
53
            $name,
54
            'Pipe "'.$name.'" failed due to exception (message: "'.$e->getMessage().'", code: '.$e->getCode().').',
55
            static::EXCEPTION_THROWN,
56
            $e
57
        );
58
    }
59
60
    /**
61
     * Create new exception instance with REJECTED status.
62
     *
63
     * @param string $name
64
     *
65
     * @return static
66
     */
67
    public static function rejected(string $name)
68
    {
69
        return new static(
70
            $name,
71
            'Pipe "'.$name.'" has been rejected.',
72
            static::REJECTED
73
        );
74
    }
75
}
76