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

Stat::init()   B

Complexity

Conditions 6
Paths 17

Size

Total Lines 21
Code Lines 11

Duplication

Lines 6
Ratio 28.57 %

Code Coverage

Tests 11
CRAP Score 6.0208

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 17
nop 0
dl 6
loc 21
ccs 11
cts 12
cp 0.9167
crap 6.0208
rs 8.7624
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 Stat extends Response
8
{
9
    /**
10
     * @var \DateTimeInterface
11
     */
12
    protected $sendTime;
13
14
    /**
15
     * @var int
16
     */
17
    protected $buffered;
18
19
    /**
20
     * @var int
21
     */
22
    protected $received;
23
24
    /**
25
     * @var int
26
     */
27
    protected $rejected;
28
29 3
    public function init()
30
    {
31 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...
32 3
            $this->sendTime = \DateTimeImmutable::createFromFormat('d-m-Y H:i:s', $this->data->sendtime);
33 3
            if($this->sendTime === false) {
34
                throw new InvalidResponseException('`sendtime` does not have the correct format. Value given: '.$this->data->sendtime);
35
            }
36
        }
37
38 3
        if(isset($this->data->buffered)) {
39 3
            $this->buffered = (int)$this->data->buffered;
40
        }
41
42 3
        if(isset($this->data->received)) {
43 3
            $this->received = (int)$this->data->received;
44
        }
45
46 3
        if(isset($this->data->rejected)) {
47 3
            $this->rejected = (int)$this->data->rejected;
48
        }
49 3
    }
50
51
    /**
52
     * @return \DateTimeInterface
53
     */
54
    public function getSendTime(): \DateTimeInterface
55
    {
56
        return $this->sendTime;
57
    }
58
59
    /**
60
     * @return int
61
     */
62
    public function getBuffered(): int
63
    {
64
        return $this->buffered;
65
    }
66
67
    /**
68
     * @return int
69
     */
70
    public function getReceived(): int
71
    {
72
        return $this->received;
73
    }
74
75
    /**
76
     * @return int
77
     */
78
    public function getRejected(): int
79
    {
80
        return $this->rejected;
81
    }
82
}
83