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

SetSubscriptionAttributeResponse   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 5
dl 52
loc 52
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\SubscriptionNotExistException;
7
use AliyunMNS\Exception\InvalidArgumentException;
8
use AliyunMNS\Responses\BaseResponse;
9
use AliyunMNS\Common\XMLParser;
10
11
class SetSubscriptionAttributeResponse extends BaseResponse
12
{
13
    public function __construct()
14
    {
15
    }
16
17
    public function parseResponse($statusCode, $content)
18
    {
19
        $this->statusCode = $statusCode;
20
        if ($statusCode == 204) {
21
            $this->succeed = TRUE;
22
        } else {
23
            $this->parseErrorResponse($statusCode, $content);
24
        }
25
    }
26
27
    public function parseErrorResponse($statusCode, $content, MnsException $exception = NULL)
28
    {
29
        $this->succeed = FALSE;
30
        $xmlReader = new \XMLReader();
31
        try {
32
            $xmlReader->XML($content);
33
            $result = XMLParser::parseNormalError($xmlReader);
34
35
            if ($result['Code'] == Constants::INVALID_ARGUMENT)
36
            {
37
                throw new InvalidArgumentException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
38
            }
39
            if ($result['Code'] == Constants::SUBSCRIPTION_NOT_EXIST)
40
            {
41
                throw new SubscriptionNotExistException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
42
            }
43
            throw new MnsException($statusCode, $result['Message'], $exception, $result['Code'], $result['RequestId'], $result['HostId']);
44
        }
45
        catch (\Exception $e)
46
        {
47
            if ($exception != NULL) {
48
                throw $exception;
49
            }
50
            elseif ($e instanceof MnsException)
51
            {
52
                throw $e;
53
            }
54
            else
55
            {
56
                throw new MnsException($statusCode, $e->getMessage());
57
            }
58
        } catch (\Throwable $t) {
59
            throw new MnsException($statusCode, $t->getMessage());
60
        }
61
    }
62
}
63
64
?>
65