Job::failedException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Zenstruck\Queue;
4
5
/**
6
 * @author Kevin Bond <[email protected]>
7
 */
8
final class Job implements \JsonSerializable
9
{
10
    private $payload;
11
    private $attempts;
12
    private $id;
13
    private $failedException;
14
15
    /**
16
     * @param Payload $payload
17
     * @param int     $attempts
18
     * @param mixed   $id
19
     */
20 17
    public function __construct(Payload $payload, $attempts = 1, $id = null)
21
    {
22 17
        $this->payload = $payload;
23 17
        $this->attempts = $attempts;
24 17
        $this->id = $id;
25 17
    }
26
27
    /**
28
     * @return string
29
     */
30 9
    public function serializedEnvelope()
31
    {
32 9
        return $this->payload->serializedEnvelope();
33
    }
34
35
    /**
36
     * @return string
37
     */
38 5
    public function metadata()
39
    {
40 5
        return $this->payload->metadata();
41
    }
42
43
    /**
44
     * @return Payload
45
     */
46 3
    public function payload()
47
    {
48 3
        return $this->payload;
49
    }
50
51
    /**
52
     * @return int
53
     */
54 9
    public function attempts()
55
    {
56 9
        return $this->attempts;
57
    }
58
59
    /**
60
     * @return mixed
61
     */
62 2
    public function id()
63
    {
64 2
        return $this->id;
65
    }
66
67
    /**
68
     * @param \Exception $exception
69
     */
70 10
    public function fail(\Exception $exception)
71
    {
72 10
        $this->failedException = $exception;
73 10
    }
74
75
    /**
76
     * @return bool
77
     */
78 14
    public function isFailed()
79
    {
80 14
        return $this->failedException instanceof \Exception;
81
    }
82
83
    /**
84
     * @return \Exception|null
85
     */
86 7
    public function failedException()
87
    {
88 7
        return $this->failedException;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 1
    public function jsonSerialize()
95
    {
96
        return [
97 1
            'metadata' => $this->metadata(),
98 1
            'failed' => $this->isFailed(),
99 1
            'attempts' => $this->attempts(),
100 1
        ];
101
    }
102
}
103