Completed
Pull Request — master (#23)
by
unknown
07:29
created

FailedJob::hasRetryStrategy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace ResqueBundle\Resque;
4
5
/**
6
 * Class FailedJob
7
 * @package ResqueBundle\Resque
8
 */
9
class FailedJob
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $data;
15
16
    /**
17
     * @param array $data Contains the failed job data
18
     */
19
    public function __construct(array $data)
20
    {
21
        $this->data = $data;
22
    }
23
24
    /**
25
     * @return mixed
26
     */
27
    public function getFailedAt()
28
    {
29
        return $this->data['failed_at'];
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getName()
36
    {
37
        return $this->data['payload']['class'];
38
    }
39
40
    /**
41
     * @return int
42
     */
43
    public function getId()
44
    {
45
        return $this->data['payload']['id'];
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getQueueName()
52
    {
53
        return $this->data['queue'];
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getWorkerName()
60
    {
61
        return $this->data['worker'];
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getExceptionClass()
68
    {
69
        return $this->data['exception'];
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getError()
76
    {
77
        return $this->data['error'];
78
    }
79
80
    /**
81
     * @return mixed
82
     */
83
    public function getBacktrace()
84
    {
85
        return $this->data['backtrace'];
86
    }
87
88
    /**
89
     * @return array
90
     */
91
    public function getArgs()
92
    {
93
        return $this->data['payload']['args'];
94
    }
95
96
    /**
97
     * @return bool
98
     */
99
    public function hasRetryStrategy()
100
    {
101
        return
102
            array_key_exists('resque.retry_strategy', $this->data['payload']['args'][0]) &&
103
            count($this->data['payload']['args'][0]['resque.retry_strategy']) > 0;
104
    }
105
106
    /**
107
     * @return bool
108
     */
109
    public function isLastAttempt()
110
    {
111
        return
112
            array_key_exists('resque.retry_attempt', $this->data['payload']['args'][0]) &&
113
            count($this->data['payload']['args'][0]['resque.retry_strategy']) === $this->data['payload']['args'][0]['resque.retry_attempt'];
114
    }
115
}
116