MaxAttemptsReached::maxAttempts()   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\Event;
4
5
use SimpleBus\Message\Name\NamedMessage;
6
use Zenstruck\Queue\Job;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class MaxAttemptsReached implements NamedMessage
12
{
13
    private $job;
14
    private $maxAttempts;
15
16
    /**
17
     * @param Job $job
18
     * @param int $maxAttempts
19
     */
20 5
    public function __construct(Job $job, $maxAttempts)
21
    {
22 5
        if (!$job->isFailed()) {
23 1
            throw new \LogicException('Job is not marked as failed.');
24
        }
25
26 4
        $this->job = $job;
27 4
        $this->maxAttempts = $maxAttempts;
28 4
    }
29
30
    /**
31
     * @return Job
32
     */
33 2
    public function job()
34
    {
35 2
        return $this->job;
36
    }
37
38
    /**
39
     * @return int
40
     */
41 2
    public function maxAttempts()
42
    {
43 2
        return $this->maxAttempts;
44
    }
45
46
    /**
47
     * @return \Exception
48
     */
49 1
    public function exception()
50
    {
51 1
        return $this->job->failedException();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    public static function messageName()
58
    {
59 1
        return 'queue.max_attempts_reached';
60
    }
61
}
62