Completed
Push — master ( 4cdc8a...86c904 )
by Joachim
01:27
created

Details::getState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Loevgaard\Linkmobility\Response\BatchStatus;
3
4
use Loevgaard\Linkmobility\Exception\InvalidResponseException;
5
use Loevgaard\Linkmobility\Response\Response;
6
7
class Details extends Response
8
{
9
    /**
10
     * The batch is ready for processing. The batch will be processed shortly after sendtime has passed.
11
     */
12
    const STATE_QUEUED = 'QUEUED';
13
14
    /**
15
     * The batch is currently processing. Messages are being sent, and the "buffered",
16
     * "received" and "rejected" numbers will be updated as it is processed.
17
     */
18
    const STATE_RUNNING = 'RUNNING';
19
20
    /**
21
     * The batch has finished processing. Up to 48 hours after this the messages will still be sent out for delivery.
22
     */
23
    const STATE_DONE = 'DONE';
24
25
    /**
26
     * @var \DateTimeInterface
27
     */
28
    protected $sendTime;
29
30
    /**
31
     * @var int
32
     */
33
    protected $batchId;
34
35
    /**
36
     * @var string
37
     */
38
    protected $state;
39
40 3
    public function init()
41
    {
42 3 View Code Duplication
        if(isset($this->data->sendtime)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43 3
            $this->sendTime = \DateTimeImmutable::createFromFormat('d-m-Y H:i:s', $this->data->sendtime);
44 3
            if($this->sendTime === false) {
45
                throw new InvalidResponseException('`sendtime` does not have the correct format. Value given: '.$this->data->sendtime);
46
            }
47
        }
48
49 3
        if(isset($this->data->batchid)) {
50 3
            $this->batchId = (int)$this->data->batchid;
51
        }
52
53 3
        $this->state = $this->data->state ?? null;
54 3
    }
55
56
    /**
57
     * @return bool
58
     */
59
    public function isDone() : bool
60
    {
61
        return $this->state === static::STATE_DONE;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function isQueued() : bool
68
    {
69
        return $this->state === static::STATE_QUEUED;
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    public function isRunning() : bool
76
    {
77
        return $this->state === static::STATE_RUNNING;
78
    }
79
80
    /**
81
     * @return \DateTimeInterface
82
     */
83
    public function getSendTime(): \DateTimeInterface
84
    {
85
        return $this->sendTime;
86
    }
87
88
    /**
89
     * @return int
90
     */
91
    public function getBatchId(): int
92
    {
93
        return $this->batchId;
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getState(): string
100
    {
101
        return $this->state;
102
    }
103
}
104