Message   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 103
Duplicated Lines 14.56 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 103
rs 10
wmc 10
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setCode() 0 5 1
A getCode() 0 4 1
A setDescription() 0 5 1
A getDescription() 0 4 1
A isOnTime() 0 4 1
A isRescheduled() 0 4 1
A isReturnedToShipper() 0 4 1
A fromXml() 15 15 3

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 namespace SimpleUPS\Track\SmallPackage;
2
3
/**
4
 * What kind of message the custom can provide
5
 * @since 1.0
6
 */
7
8
class Message extends \SimpleUPS\Model
9
{
10
11
    private
12
        $CODE_ON_TIME = '01',
13
        $CODE_RESCHEDULED = '02',
14
        $CODE_RETURNED_TO_SHIPPER = '03';
15
    private
16
        /* @var string $code */
17
        $code,
18
19
        /* @var string $description */
20
        $description;
21
22
    /**
23
     * @internal
24
     *
25
     * @param string $code
26
     *
27
     * @return Message
28
     */
29
    public function setCode($code)
30
    {
31
        $this->code = (string)$code;
32
        return $this;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getCode()
39
    {
40
        return $this->code;
41
    }
42
43
    /**
44
     * @internal
45
     *
46
     * @param string $description
47
     *
48
     * @return Message
49
     */
50
    public function setDescription($description)
51
    {
52
        $this->description = (string)$description;
53
        return $this;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getDescription()
60
    {
61
        return $this->description;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function isOnTime()
68
    {
69
        return $this->getCode() == $this->CODE_ON_TIME;
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    public function isRescheduled()
76
    {
77
        return $this->getCode() == $this->CODE_RESCHEDULED;
78
    }
79
80
    /**
81
     * @return bool
82
     */
83
    public function isReturnedToShipper()
84
    {
85
        return $this->getCode() == $this->CODE_RETURNED_TO_SHIPPER;
86
    }
87
88
    /**
89
     * @internal
90
     *
91
     * @param \SimpleXMLElement $xml
92
     *
93
     * @return Message
94
     */
95 View Code Duplication
    public static function fromXml(\SimpleXMLElement $xml)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
96
    {
97
        $message = new Message();
98
        $message->setIsResponse();
99
100
        if (isset($xml->Code)) {
101
            $message->setCode($xml->Code);
102
        }
103
104
        if (isset($xml->Description)) {
105
            $message->setDescription($xml->Description);
106
        }
107
108
        return $message;
109
    }
110
}