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

ListTopicResponse::parseResponse()   D

Complexity

Conditions 10
Paths 34

Size

Total Lines 46
Code Lines 27

Duplication

Lines 46
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 46
loc 46
rs 4.983
cc 10
eloc 27
nc 34
nop 2

How to fix   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\Responses;
3
4
use AliyunMNS\Exception\MnsException;
5
use AliyunMNS\Responses\BaseResponse;
6
use AliyunMNS\Common\XMLParser;
7
8
class ListTopicResponse extends BaseResponse
9
{
10
    private $topicNames;
11
    private $nextMarker;
12
13
    public function __construct()
14
    {
15
        $this->topicNames = array();
16
        $this->nextMarker = NULL;
17
    }
18
19
    public function isFinished()
20
    {
21
        return $this->nextMarker == NULL;
22
    }
23
24
    public function getTopicNames()
25
    {
26
        return $this->topicNames;
27
    }
28
29
    public function getNextMarker()
30
    {
31
        return $this->nextMarker;
32
    }
33
34
    public function parseResponse($statusCode, $content)
35
    {
36
        $this->statusCode = $statusCode;
37
        if ($statusCode != 200) {
38
            $this->parseErrorResponse($statusCode, $content);
39
            return;
40
        }
41
42
        $this->succeed = TRUE;
43
        $xmlReader = new \XMLReader();
44
        try
45
        {
46
            $xmlReader->XML($content);
47
            while ($xmlReader->read())
48
            {
49
                if ($xmlReader->nodeType == \XMLReader::ELEMENT)
50
                {
51
                    switch ($xmlReader->name) {
52
                    case 'TopicURL':
53
                        $xmlReader->read();
54
                        if ($xmlReader->nodeType == \XMLReader::TEXT)
55
                        {
56
                            $topicName = $this->getTopicNameFromTopicURL($xmlReader->value);
57
                            $this->topicNames[] = $topicName;
58
                        }
59
                        break;
60
                    case 'NextMarker':
61
                        $xmlReader->read();
62
                        if ($xmlReader->nodeType == \XMLReader::TEXT)
63
                        {
64
                            $this->nextMarker = $xmlReader->value;
65
                        }
66
                        break;
67
                    }
68
                }
69
            }
70
        }
71
        catch (\Exception $e)
72
        {
73
            throw new MnsException($statusCode, $e->getMessage(), $e);
74
        }
75
        catch (\Throwable $t)
76
        {
77
            throw new MnsException($statusCode, $t->getMessage());
78
        }
79
    }
80
81
    private function getTopicNameFromTopicURL($topicURL)
82
    {
83
        $pieces = explode("/", $topicURL);
84
        if (count($pieces) == 5)
85
        {
86
            return $pieces[4];
87
        }
88
        return "";
89
    }
90
91
    public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
92
    {
93
        $this->succeed = FALSE;
94
        $xmlReader = new \XMLReader();
95
        try
96
        {
97
            $xmlReader->XML($content);
98
            $result = XMLParser::parseNormalError($xmlReader);
99
100
            throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
101
        }
102
        catch (\Exception $e)
103
        {
104
            if ($exception != NULL)
105
            {
106
                throw $exception;
107
            }
108
            elseif ($e instanceof MnsException)
109
            {
110
                throw $e;
111
            }
112
            else
113
            {
114
                throw new MnsException($statusCode, $e->getMessage());
115
            }
116
        }
117
        catch (\Throwable $t)
118
        {
119
            throw new MnsException($statusCode, $t->getMessage());
120
        }
121
    }
122
}
123
124
?>
125