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

BatchSendMessageResponse::parseErrorResponse()   C

Complexity

Conditions 8
Paths 27

Size

Total Lines 31
Code Lines 23

Duplication

Lines 31
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 31
loc 31
rs 5.3846
cc 8
eloc 23
nc 27
nop 3
1
<?php
2
namespace AliyunMNS\Responses;
3
4
use AliyunMNS\Constants;
5
use AliyunMNS\Exception\MnsException;
6
use AliyunMNS\Exception\BatchSendFailException;
7
use AliyunMNS\Exception\QueueNotExistException;
8
use AliyunMNS\Exception\InvalidArgumentException;
9
use AliyunMNS\Exception\MalformedXMLException;
10
use AliyunMNS\Responses\BaseResponse;
11
use AliyunMNS\Common\XMLParser;
12
use AliyunMNS\Model\SendMessageResponseItem;
13
use AliyunMNS\Traits\MessageIdAndMD5;
14
15
class BatchSendMessageResponse extends BaseResponse
16
{
17
    protected $sendMessageResponseItems;
18
19
    public function __construct()
20
    {
21
        $this->sendMessageResponseItems = array();
22
    }
23
24
    public function getSendMessageResponseItems()
25
    {
26
        return $this->sendMessageResponseItems;
27
    }
28
29
    public function parseResponse($statusCode, $content)
30
    {
31
        $this->statusCode = $statusCode;
32
        if ($statusCode == 201) {
33
            $this->succeed = TRUE;
34
        } else {
35
            $this->parseErrorResponse($statusCode, $content);
36
        }
37
38
        $xmlReader = new \XMLReader();
39
        try {
40
            $xmlReader->XML($content);
41
            while ($xmlReader->read())
42
            {
43
                if ($xmlReader->nodeType == \XMLReader::ELEMENT && $xmlReader->name == 'Message') {
44
                    $this->sendMessageResponseItems[] = SendMessageResponseItem::fromXML($xmlReader);
45
                }
46
            }
47
        } catch (\Exception $e) {
48
            throw new MnsException($statusCode, $e->getMessage(), $e);
49
        } catch (\Throwable $t) {
50
            throw new MnsException($statusCode, $t->getMessage());
51
        }
52
    }
53
54
    public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
55
    {
56
        $this->succeed = FALSE;
57
        $xmlReader = new \XMLReader();
58
        try {
59
            $xmlReader->XML($content);
60
            while ($xmlReader->read())
61
            {
62
                if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
63
                    switch ($xmlReader->name) {
64
                    case Constants::ERROR:
65
                        $this->parseNormalErrorResponse($xmlReader);
66
                        break;
67
                    default: // case Constants::Messages
68
                        $this->parseBatchSendErrorResponse($xmlReader);
69
                        break;
70
                    }
71
                }
72
            }
73
        } catch (\Exception $e) {
74
            if ($exception != NULL) {
75
                throw $exception;
76
            } elseif($e instanceof MnsException) {
77
                throw $e;
78
            } else {
79
                throw new MnsException($statusCode, $e->getMessage());
80
            }
81
        } catch (\Throwable $t) {
82
            throw new MnsException($statusCode, $t->getMessage());
83
        }
84
    }
85
86
    private function parseBatchSendErrorResponse($xmlReader)
87
    {
88
        $ex = new BatchSendFailException($this->statusCode, "BatchSendMessage Failed For Some Messages");
89
        while ($xmlReader->read())
90
        {
91
            if ($xmlReader->nodeType == \XMLReader::ELEMENT && $xmlReader->name == 'Message') {
92
                $ex->addSendMessageResponseItem( SendMessageResponseItem::fromXML($xmlReader));
93
            }
94
        }
95
        throw $ex;
96
    }
97
98
    private function parseNormalErrorResponse($xmlReader)
99
    {
100
        $result = XMLParser::parseNormalError($xmlReader);
101
        if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
102
        {
103
            throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
104
        }
105
        if ($result['Code'] == Constants::INVALID_ARGUMENT)
106
        {
107
            throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
108
        }
109
        if ($result['Code'] == Constants::MALFORMED_XML)
110
        {
111
            throw new MalformedXMLException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
112
        }
113
        throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
114
    }
115
}
116
117
?>
118