Completed
Pull Request — master (#3)
by Kevin
03:40
created

MaxAttemptsReached   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 76.92%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 51
ccs 10
cts 13
cp 0.7692
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A job() 0 4 1
A maxAttempts() 0 4 1
A messageName() 0 4 1
A __construct() 0 9 2
A exception() 0 4 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 4
    public function __construct(Job $job, $maxAttempts)
21
    {
22
        if (!$job->isFailed()) {
23
            throw new \LogicException('Job is not marked as failed.');
24
        }
25
26 4
        $this->job = $job;
27 4
        $this->maxAttempts = $maxAttempts;
28 1
    }
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
    public function exception()
50
    {
51
        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