GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch master (b10c57)
by milkmeowo
02:58
created

Message::fromXML()   D

Complexity

Conditions 24
Paths 24

Size

Total Lines 118
Code Lines 87

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 24
eloc 87
nc 24
nop 2
dl 0
loc 118
rs 4.5989
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace AliyunMNS\Model;
3
4
use AliyunMNS\Constants;
5
use AliyunMNS\Traits\MessagePropertiesForReceive;
6
7
class Message
8
{
9
    use MessagePropertiesForReceive;
10
11
    public function __construct($messageId, $messageBodyMD5, $messageBody, $enqueueTime, $nextVisibleTime, $firstDequeueTime, $dequeueCount, $priority, $receiptHandle)
12
    {
13
        $this->messageId = $messageId;
14
        $this->messageBodyMD5 = $messageBodyMD5;
15
        $this->messageBody = $messageBody;
16
        $this->enqueueTime = $enqueueTime;
17
        $this->nextVisibleTime = $nextVisibleTime;
18
        $this->firstDequeueTime = $firstDequeueTime;
19
        $this->dequeueCount = $dequeueCount;
20
        $this->priority = $priority;
21
        $this->receiptHandle = $receiptHandle;
22
    }
23
24
    static public function fromXML(\XMLReader $xmlReader, $base64)
25
    {
26
        $messageId = NULL;
27
        $messageBodyMD5 = NULL;
28
        $messageBody = NULL;
29
        $enqueueTime = NULL;
30
        $nextVisibleTime = NULL;
31
        $firstDequeueTime = NULL;
32
        $dequeueCount = NULL;
33
        $priority = NULL;
34
        $receiptHandle = NULL;
35
36
        while ($xmlReader->read())
37
        {
38
            switch ($xmlReader->nodeType)
39
            {
40
            case \XMLReader::ELEMENT:
41
                switch ($xmlReader->name) {
42
                case Constants::MESSAGE_ID:
43
                    $xmlReader->read();
44
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
45
                    {
46
                        $messageId = $xmlReader->value;
47
                    }
48
                    break;
49
                case Constants::MESSAGE_BODY_MD5:
50
                    $xmlReader->read();
51
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
52
                    {
53
                        $messageBodyMD5 = $xmlReader->value;
54
                    }
55
                    break;
56
                case Constants::MESSAGE_BODY:
57
                    $xmlReader->read();
58
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
59
                    {
60
                        if ($base64 == TRUE) {
61
                            $messageBody = base64_decode($xmlReader->value);
62
                        } else {
63
                            $messageBody = $xmlReader->value;
64
                        }
65
                    }
66
                    break;
67
                case Constants::ENQUEUE_TIME:
68
                    $xmlReader->read();
69
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
70
                    {
71
                        $enqueueTime = $xmlReader->value;
72
                    }
73
                    break;
74
                case Constants::NEXT_VISIBLE_TIME:
75
                    $xmlReader->read();
76
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
77
                    {
78
                        $nextVisibleTime = $xmlReader->value;
79
                    }
80
                    break;
81
                case Constants::FIRST_DEQUEUE_TIME:
82
                    $xmlReader->read();
83
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
84
                    {
85
                        $firstDequeueTime = $xmlReader->value;
86
                    }
87
                    break;
88
                case Constants::DEQUEUE_COUNT:
89
                    $xmlReader->read();
90
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
91
                    {
92
                        $dequeueCount = $xmlReader->value;
93
                    }
94
                    break;
95
                case Constants::PRIORITY:
96
                    $xmlReader->read();
97
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
98
                    {
99
                        $priority = $xmlReader->value;
100
                    }
101
                    break;
102
                case Constants::RECEIPT_HANDLE:
103
                    $xmlReader->read();
104
                    if ($xmlReader->nodeType == \XMLReader::TEXT)
105
                    {
106
                        $receiptHandle = $xmlReader->value;
107
                    }
108
                    break;
109
                }
110
                break;
111
            case \XMLReader::END_ELEMENT:
112
                if ($xmlReader->name == 'Message')
113
                {
114
                    $message = new Message(
115
                        $messageId,
116
                        $messageBodyMD5,
117
                        $messageBody,
118
                        $enqueueTime,
119
                        $nextVisibleTime,
120
                        $firstDequeueTime,
121
                        $dequeueCount,
122
                        $priority,
123
                        $receiptHandle);
124
                    return $message;
125
                }
126
                break;
127
            }
128
        }
129
130
        $message = new Message(
131
            $messageId,
132
            $messageBodyMD5,
133
            $messageBody,
134
            $enqueueTime,
135
            $nextVisibleTime,
136
            $firstDequeueTime,
137
            $dequeueCount,
138
            $priority,
139
            $receiptHandle);
140
141
        return $message;
142
    }
143
}
144
145
?>
146