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
Push — master ( 173046...a8b00f )
by sebastian
01:42
created

RequestFactory   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
dl 0
loc 154
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createPutRequest() 0 7 1
A createDeleteRequest() 0 6 1
A createReportRequest() 0 7 1
A createPropFindRequest() 0 7 1
C createHeadersFor() 0 44 8
A createGetRequest() 0 6 1
A createMakeCalendarRequest() 0 7 1
A createOptionsRequest() 0 6 1
1
<?php namespace CalDAVClient\Facade\Utils;
2
/**
3
 * Copyright 2017 OpenStack Foundation
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 * Unless required by applicable law or agreed to in writing, software
9
 * distributed under the License is distributed on an "AS IS" BASIS,
10
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
 * See the License for the specific language governing permissions and
12
 * limitations under the License.
13
 **/
14
15
use GuzzleHttp\Psr7\Request;
16
17
/**
18
 * Class RequestFactory
19
 * @package CalDAVClient\Facade\Utils
20
 */
21
final class RequestFactory
22
{
23
24
    /**
25
     * @param string $http_method
26
     * @param array $params
27
     * @return array
28
     */
29
    static private function createHeadersFor($http_method, array $params = []){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
30
        switch ($http_method){
31
            case HttpMethods::PropFind:
32
            case HttpMethods::Options:
33
            case HttpMethods::Report:
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
34
            {
35
                return  [
36
                    Headers::Depth        => $params[0],
37
                    Headers::Prefer       => "return-minimal",
38
                    Headers::ContentType  => ContentTypes::Xml
39
                ];
40
            }
41
            break;
42
            case HttpMethods::Delete:
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
43
            {
44
                return [
45
                    Headers::IfMatch =>  $params[0],
46
                ];
47
            }
48
            break;
49
            case HttpMethods::MakeCalendar:
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
50
            {
51
                return [
52
                    Headers::ContentType  => ContentTypes::Xml
53
                ];
54
            }
55
            break;
56
            case HttpMethods::Put:
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
57
            {
58
               $etag = $params[0];
59
               if(empty($etag)){
60
                   return [
61
                       Headers::ContentType  => ContentTypes::Calendar,
62
                       Headers::IfNotMatch   => '*',
63
                   ];
64
               }
65
               return [
66
                   Headers::ContentType  => ContentTypes::Calendar,
67
                   Headers::IfMatch      => $etag
68
               ];
69
            }
70
            break;
71
        }
72
        return [];
73
    }
74
    /**
75
    * @param string $url
76
    * @param string $body
77
    * @param int $depth
78
    * @return Request
79
    */
80
    static public function createPropFindRequest($url , $body, $depth = 1){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
81
        return new Request
82
        (
83
            HttpMethods::PropFind,
84
            $url ,
85
            self::createHeadersFor(HttpMethods::PropFind, [$depth]),
86
            $body
87
        );
88
    }
89
90
    /**
91
     * @param string $url
92
     * @param string $body
93
     * @return Request
94
     */
95
    static public function createMakeCalendarRequest($url , $body){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
96
        return new Request
97
        (
98
            HttpMethods::MakeCalendar,
99
            $url,
100
            self::createHeadersFor(HttpMethods::MakeCalendar),
101
            $body
102
        );
103
    }
104
105
    /**
106
     * @param string $url
107
     * @param int $depth
108
     * @return Request
109
     */
110
    static public function createOptionsRequest($url, $depth = 1){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
111
        return new Request
112
        (
113
            HttpMethods::Options,
114
            $url,
115
            self::createHeadersFor(HttpMethods::Options, [$depth])
116
        );
117
    }
118
119
    /**
120
     * @param string $url
121
     * @param string $body
122
     * @param int $depth
123
     * @return Request
124
     */
125
    static public function createReportRequest($url , $body, $depth = 1){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
126
        return new Request
127
        (
128
            HttpMethods::Report,
129
            $url,
130
            self::createHeadersFor(HttpMethods::Report, [$depth]),
131
            $body
132
        );
133
    }
134
135
    /**
136
     * @param string $url
137
     * @param string $etag
138
     * @return Request
139
     */
140
    static public function createDeleteRequest($url , $etag){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
141
        return new Request
142
        (
143
            HttpMethods::Delete,
144
            $url,
145
            self::createHeadersFor(HttpMethods::Delete, [$etag])
146
        );
147
    }
148
149
    /**
150
     * @param string $url
151
     * @return Request
152
     */
153
    static public function createGetRequest($url){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
154
        return new Request
155
        (
156
            HttpMethods::Get,
157
            $url,
158
            self::createHeadersFor(HttpMethods::Get)
159
        );
160
    }
161
162
    /**
163
     * @param string $url
164
     * @param string $body
165
     * @param string $etag
166
     * @return Request
167
     */
168
    static public function createPutRequest($url, $body, $etag = null){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
169
        return new Request
170
        (
171
            HttpMethods::Put,
172
            $url,
173
            self::createHeadersFor(HttpMethods::Put, [$etag]),
174
            $body
175
        );
176
    }
177
178
}