Message::fromXml()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 4
nop 1
dl 15
loc 15
rs 9.4285
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
}