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

Details   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 97
Duplicated Lines 6.19 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 38.1%

Importance

Changes 0
Metric Value
dl 6
loc 97
ccs 8
cts 21
cp 0.381
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 6 15 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 \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