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

Stat   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 81
Duplicated Lines 7.41 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 6
loc 81
ccs 19
cts 21
cp 0.9048
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 6 23 6
A getSendTime() 0 4 1
A getBuffered() 0 4 1
A getReceived() 0 4 1
A getRejected() 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 Stat extends Response
8
{
9
    /**
10
     * @var \DateTimeImmutable
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
    /**
30
     * @throws InvalidResponseException
31
     */
32 1
    public function init() : void
33
    {
34 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...
35 1
            $this->sendTime = \DateTimeImmutable::createFromFormat('d-m-Y H:i:s', $this->data->sendtime);
36 1
            if ($this->sendTime === false) {
37
                throw new InvalidResponseException(
38
                    '`sendtime` does not have the correct format. Value given: '.$this->data->sendtime
39
                );
40
            }
41
        }
42
43 1
        if (isset($this->data->buffered)) {
44 1
            $this->buffered = (int)$this->data->buffered;
45
        }
46
47 1
        if (isset($this->data->received)) {
48 1
            $this->received = (int)$this->data->received;
49
        }
50
51 1
        if (isset($this->data->rejected)) {
52 1
            $this->rejected = (int)$this->data->rejected;
53
        }
54 1
    }
55
56
    /**
57
     * @return \DateTimeImmutable
58
     */
59 1
    public function getSendTime(): \DateTimeImmutable
60
    {
61 1
        return $this->sendTime;
62
    }
63
64
    /**
65
     * @return int
66
     */
67 1
    public function getBuffered(): int
68
    {
69 1
        return $this->buffered;
70
    }
71
72
    /**
73
     * @return int
74
     */
75 1
    public function getReceived(): int
76
    {
77 1
        return $this->received;
78
    }
79
80
    /**
81
     * @return int
82
     */
83 1
    public function getRejected(): int
84
    {
85 1
        return $this->rejected;
86
    }
87
}
88