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.
Passed
Pull Request — master (#16)
by
unknown
03:57
created

GenericSinglePROPFINDCalDAVResponse::parse()   C

Complexity

Conditions 13
Paths 16

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 33
rs 6.6166
c 0
b 0
f 0
cc 13
nc 16
nop 0

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 namespace CalDAVClient\Facade\Responses;
2
3
/**
4
 * Copyright 2017 OpenStack Foundation
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 * Unless required by applicable law or agreed to in writing, software
10
 * distributed under the License is distributed on an "AS IS" BASIS,
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 * See the License for the specific language governing permissions and
13
 * limitations under the License.
14
 **/
15
16
use CalDAVClient\Facade\Exceptions\ForbiddenQueryException;
17
use CalDAVClient\Facade\Exceptions\NotValidGenericSingleCalDAVResponseException;
18
19
/**
20
 * Class GenericSinglePROPFINDCalDAVResponse
21
 * @package CalDAVClient\Facade\Responses
22
 * @see https://tools.ietf.org/html/rfc2518#section-11
23
 */
24
class GenericSinglePROPFINDCalDAVResponse extends AbstractCalDAVResponse
25
{
26
    /**
27
     * @var array
28
     */
29
    protected $found_props = [];
30
31
    /**
32
     * @var array
33
     */
34
    protected $not_found_props = [];
35
36
    /**
37
     * @return $this
38
     * @throws ForbiddenQueryException
39
     * @throw NotValidGenericSingleCalDAVResponseException
40
     */
41
    protected function parse()
42
    {
43
44
        if (!$this->isValid()) throw new NotValidGenericSingleCalDAVResponseException();
45
        if (!isset($this->content['response']['propstat'])) return $this;
46
        if (isset($this->content['response']['propstat']['prop']) && isset($this->content['response']['propstat']['status'])) {
47
            // all props found
48
            $status = $this->content['response']['propstat']['status'];
49
            if ($status == AbstractCalDAVResponse::HttpOKStatus) {
50
                $this->found_props = $this->content['response']['propstat']['prop'];
51
                $this->not_found_props = null;
52
            }
53
            if ($status == AbstractCalDAVResponse::HttpNotFoundStatus) {
54
                $this->not_found_props = $this->content['response']['propstat']['prop'];
55
                $this->found_props = null;
56
            }
57
            if ($status == AbstractCalDAVResponse::HttpForbiddenStatus) {
58
                throw new ForbiddenQueryException();
59
            }
60
            return $this;
61
        }
62
        // multi props ( found or not found)
63
        foreach ($this->content['response']['propstat'] as $propstat) {
64
65
            if (!isset($propstat['status']) || !isset($propstat['prop'])) continue;
66
67
            if ($propstat['status'] == AbstractCalDAVResponse::HttpOKStatus)
68
                $this->found_props = $propstat['prop'];
69
70
            if ($propstat['status'] == AbstractCalDAVResponse::HttpNotFoundStatus)
71
                $this->not_found_props = $propstat['prop'];
72
        }
73
        return $this;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    protected function isValid()
80
    {
81
        return parent::isValid() ;
82
    }
83
84
    /**
85
     * @return string|null
86
     */
87
    public function getHRef()
88
    {
89
        return isset($this->content['response']['href']) ? $this->content['response']['href'] : null;
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function getFoundProps() {
96
        return $this->found_props;
97
    }
98
99
    /**
100
     * @return array
101
     */
102
    public function getNotFoundProps() {
103
        return $this->not_found_props;
104
    }
105
106
    /**
107
     * @return bool
108
     */
109
    public function isSuccessFull()
110
    {
111
        return $this->code == HttpResponse::HttpCodeMultiResponse;
112
    }
113
}