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 ( cfbc8c...760777 )
by sebastian
01:23
created

RequestFactory::createGetRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 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
    private static function createHeadersFor($http_method, array $params = []){
30
        switch ($http_method){
31
            case HttpMethods::PropFind:
32
            case HttpMethods::Options:
33
            case HttpMethods::Report:
34
                return  [
35
                    Headers::Depth        => $params[0],
36
                    Headers::Prefer       => "return-minimal",
37
                    Headers::ContentType  => ContentTypes::Xml
38
                ];
39
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
40
            case HttpMethods::Delete:
41
                $etag = $params[0];
42
                if(!empty($etag))
43
                return [
44
                    Headers::IfMatch =>  $params[0],
45
                ];
46
                return [];
47
            break;
48
            case HttpMethods::MakeCalendar:
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

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

    doSomethingElse(); //wrong
    break;

}

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

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