Test Failed
Push — master ( 79aaa0...94c60c )
by Hirofumi
02:46
created

JobFlight::acknowledge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Shippinno\Job\Application\Messaging;
4
5
use DateTimeImmutable;
6
7
class JobFlight
8
{
9
    /**
10
     * @string
11
     */
12
    private const RESULT_ACKNOWLEDGED = 'acknowledged';
13
14
    /**
15
     * @string
16
     */
17
    private const RESULT_ABANDONED = 'abandoned';
18
19
    /**
20
     * @string
21
     */
22
    private const RESULT_REQUEUED = 'requeued';
23
24
    /**
25
     * @string
26
     */
27
    private const RESULT_REJECTED = 'rejected';
28
29
    /**
30
     * @string
31
     */
32
    private const RESULT_LET_GO = 'let_go';
33
34
    /**
35
     * @var int
36
     */
37
    private $id;
38
39
    /**
40
     * @var int
41
     */
42
    private $jobId;
43
44
    /**
45
     * @var string
46
     */
47
    private $jobName;
48
49
    /**
50
     * @var string
51
     */
52
    private $queue;
53
54
    /**
55
     * @var DateTimeImmutable
56
     */
57
    private $departure;
58
59
    /**
60
     * @var null|DateTimeImmutable
61
     */
62
    private $arrival;
63
64
    /**
65
     * @var string|string
66
     */
67
    private $result;
68
69
    /**
70
     * @param int $jobId
71
     * @param string $jobName
72
     * @param string $queue
73
     * @throws \Exception
74
     */
75
    public function __construct(int $jobId, string $jobName, string $queue)
76
    {
77
        $this->jobId = $jobId;
78
        $this->jobName = $jobName;
79
        $this->queue = $queue;
80
        $this->departure = new DateTimeImmutable;
81
        $this->arrival = null;
82
        $this->result = null;
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function jobId(): int
89
    {
90
        return $this->jobId;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function jobName(): string
97
    {
98
        return $this->jobName;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function queue(): string
105
    {
106
        return $this->queue;
107
    }
108
109
    /**
110
     * @return void
111
     */
112
    public function acknowledge(): void
113
    {
114
        $this->arrival = new DateTimeImmutable;
115
        $this->result = self::RESULT_ACKNOWLEDGED;
116
    }
117
118
    /**
119
     * @return void
120
     */
121
    public function abandoned(): void
122
    {
123
        $this->arrival = new DateTimeImmutable;
124
        $this->result = self::RESULT_ABANDONED;
125
    }
126
127
    /**
128
     * @return void
129
     */
130
    public function requeued(): void
131
    {
132
        $this->arrival = new DateTimeImmutable;
133
        $this->result = self::RESULT_REQUEUED;
134
    }
135
136
    /**
137
     * @throws void
138
     */
139
    public function rejected(): void
140
    {
141
        $this->arrival = new DateTimeImmutable;
142
        $this->result = self::RESULT_REJECTED;
143
    }
144
145
    /**
146
     * @return void
147
     */
148
    public function letGo(): void
149
    {
150
        $this->arrival = new DateTimeImmutable;
151
        $this->result = self::RESULT_LET_GO;
152
    }
153
}
154