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

Stat   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 7.89 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 55%

Importance

Changes 0
Metric Value
dl 6
loc 76
ccs 11
cts 20
cp 0.55
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 2

5 Methods

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