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.
Completed
Push — master ( 9a7ea4...53d770 )
by Yang
02:32
created

Message   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 137
Duplicated Lines 40.88 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 25
c 3
b 0
f 0
lcom 0
cbo 1
dl 56
loc 137
rs 10

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 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