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

BatchDeleteMessageResponse   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 80
Duplicated Lines 62.5 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 19
c 2
b 0
f 0
lcom 1
cbo 8
dl 50
loc 80
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\Responses;
3
4
use AliyunMNS\Constants;
5
use AliyunMNS\Exception\MnsException;
6
use AliyunMNS\Exception\QueueNotExistException;
7
use AliyunMNS\Exception\InvalidArgumentException;
8
use AliyunMNS\Exception\BatchDeleteFailException;
9
use AliyunMNS\Exception\ReceiptHandleErrorException;
10
use AliyunMNS\Responses\BaseResponse;
11
use AliyunMNS\Common\XMLParser;
12
use AliyunMNS\Model\DeleteMessageErrorItem;
13
14
class BatchDeleteMessageResponse extends BaseResponse
15
{
16
    public function __construct()
17
    {
18
    }
19
20
    public function parseResponse($statusCode, $content)
21
    {
22
        $this->statusCode = $statusCode;
23
        if ($statusCode == 204) {
24
            $this->succeed = TRUE;
25
        } else {
26
            $this->parseErrorResponse($statusCode, $content);
27
        }
28
    }
29
30
    public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
31
    {
32
        $this->succeed = FALSE;
33
        $xmlReader = new \XMLReader();
34
        try {
35
            $xmlReader->XML($content);
36
            while ($xmlReader->read())
37
            {
38
                if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
39
                    switch ($xmlReader->name) {
40
                    case Constants::ERROR:
41
                        $this->parseNormalErrorResponse($xmlReader);
42
                        break;
43
                    default: // case Constants::Messages
44
                        $this->parseBatchDeleteErrorResponse($xmlReader);
45
                        break;
46
                    }
47
                }
48
            }
49
        } catch (\Exception $e) {
50
            if ($exception != NULL) {
51
                throw $exception;
52
            } elseif($e instanceof MnsException) {
53
                throw $e;
54
            } else {
55
                throw new MnsException($statusCode, $e->getMessage());
56
            }
57
        } catch (\Throwable $t) {
58
            throw new MnsException($statusCode, $t->getMessage());
59
        }
60
    }
61
62
    private function parseBatchDeleteErrorResponse($xmlReader)
63
    {
64
        $ex = new BatchDeleteFailException($this->statusCode, "BatchDeleteMessage Failed For Some ReceiptHandles");
65
        while ($xmlReader->read())
66
        {
67
            if ($xmlReader->nodeType == \XMLReader::ELEMENT && $xmlReader->name == Constants::ERROR) {
68
                $ex->addDeleteMessageErrorItem( DeleteMessageErrorItem::fromXML($xmlReader));
69
            }
70
        }
71
        throw $ex;
72
    }
73
74
    private function parseNormalErrorResponse($xmlReader)
75
    {
76
        $result = XMLParser::parseNormalError($xmlReader);
77
78
        if ($result['Code'] == Constants::INVALID_ARGUMENT)
79
        {
80
            throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
81
        }
82
        if ($result['Code'] == Constants::QUEUE_NOT_EXIST)
83
        {
84
            throw new QueueNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
85
        }
86
        if ($result['Code'] == Constants::RECEIPT_HANDLE_ERROR)
87
        {
88
            throw new ReceiptHandleErrorException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
89
        }
90
91
        throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
92
    }
93
}
94
95
?>
96