Completed
Push — master ( 8f139f...a8687a )
by Joachim
04:58
created

Details   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 102
Duplicated Lines 5.88 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 6
loc 102
ccs 14
cts 22
cp 0.6364
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 6 17 4
A isDone() 0 4 1
A isQueued() 0 4 1
A isRunning() 0 4 1
A getSendTime() 0 4 1
A getBatchId() 0 4 1
A getState() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 \DateTimeImmutable
27
     */
28
    protected $sendTime;
29
30
    /**
31
     * @var int
32
     */
33
    protected $batchId;
34
35
    /**
36
     * @var string
37
     */
38
    protected $state;
39
40
    /**
41
     * @throws InvalidResponseException
42
     */
43 1
    public function init() : void
44
    {
45 1 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...
46 1
            $this->sendTime = \DateTimeImmutable::createFromFormat('d-m-Y H:i:s', $this->data->sendtime);
47 1
            if ($this->sendTime === false) {
48
                throw new InvalidResponseException(
49
                    '`sendtime` does not have the correct format. Value given: '.$this->data->sendtime
50
                );
51
            }
52
        }
53
54 1
        if (isset($this->data->batchid)) {
55 1
            $this->batchId = (int)$this->data->batchid;
56
        }
57
58 1
        $this->state = $this->data->state ?? null;
59 1
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function isDone() : bool
65
    {
66
        return $this->state === static::STATE_DONE;
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function isQueued() : bool
73
    {
74
        return $this->state === static::STATE_QUEUED;
75
    }
76
77
    /**
78
     * @return bool
79
     */
80
    public function isRunning() : bool
81
    {
82
        return $this->state === static::STATE_RUNNING;
83
    }
84
85
    /**
86
     * @return \DateTimeImmutable
87
     */
88 1
    public function getSendTime(): \DateTimeImmutable
89
    {
90 1
        return $this->sendTime;
91
    }
92
93
    /**
94
     * @return int
95
     */
96 1
    public function getBatchId(): int
97
    {
98 1
        return $this->batchId;
99
    }
100
101
    /**
102
     * @return string
103
     */
104 1
    public function getState(): string
105
    {
106 1
        return $this->state;
107
    }
108
}
109