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.

GenericSinglePROPFINDCalDAVResponse::parse()   C
last analyzed

Complexity

Conditions 13
Paths 16

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 33
rs 6.6166
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 ($this->statusMatches($status, AbstractCalDAVResponse::HttpOKStatus)) {
50
                $this->found_props = $this->content['response']['propstat']['prop'];
51
                $this->not_found_props = null;
52
            }
53
            if ($this->statusMatches($status, AbstractCalDAVResponse::HttpNotFoundStatus)) {
54
                $this->not_found_props = $this->content['response']['propstat']['prop'];
55
                $this->found_props = null;
56
            }
57
            if ($this->statusMatches($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 ($this->statusMatches($propstat['status'], AbstractCalDAVResponse::HttpOKStatus))
68
                $this->found_props = $propstat['prop'];
69
70
            if ($this->statusMatches($propstat['status'], AbstractCalDAVResponse::HttpNotFoundStatus))
71
                $this->not_found_props = $propstat['prop'];
72
        }
73
        return $this;
74
    }
75
76
    /**
77
     * @param string $responseStatus
78
     * @param string $desiredStatus
79
     * @return bool
80
     */
81
    protected function statusMatches($responseStatus, $desiredStatus)
82
    {
83
      return strtoupper($responseStatus) == $desiredStatus;
84
    }
85
86
    /**
87
     * @return bool
88
     */
89
    protected function isValid()
90
    {
91
        return parent::isValid() ;
92
    }
93
94
    /**
95
     * @return string|null
96
     */
97
    public function getHRef()
98
    {
99
        return isset($this->content['response']['href']) ? $this->content['response']['href'] : null;
100
    }
101
102
    /**
103
     * @return bool
104
     */
105
    public function isSuccessFull()
106
    {
107
        return $this->code == HttpResponse::HttpCodeMultiResponse;
108
    }
109
}
110