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

CalDAVRequestFactory::build()   C

Complexity

Conditions 17
Paths 17

Size

Total Lines 36
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 36
rs 5.2166
c 0
b 0
f 0
cc 17
nc 17
nop 2

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\Requests;
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
/**
16
 * Class CalDAVRequestFactory
17
 * @package CalDAVClient\Facade\Requests
18
 */
19
final class CalDAVRequestFactory implements ICalDAVRequestFactory
20
{
21
    private function __construct(){}
22
23
    /**
24
     * @var ICalDAVRequestFactory
25
     */
26
    private static $instance;
27
28
    /**
29
     * @return ICalDAVRequestFactory
30
     */
31
    public static function getInstance(){
32
        if(is_null(self::$instance)) self::$instance = new CalDAVRequestFactory();
33
        return self::$instance;
34
    }
35
36
    /**
37
     * Override which class is used to create new request objects.
38
     * @param ICalDAVRequestFactory $factory
39
     */
40
    public static function setInstance(ICalDAVRequestFactory $factory) {
41
        self::$instance = $factory;
42
    }
43
44
    /**
45
     * @param string $type
46
     * @param array $params
47
     * @return IAbstractWebDAVRequest|null
48
     * @throws \InvalidArgumentException
49
     */
50
    public function build($type, $params = []){
51
        switch(strtoupper($type)){
52
            case self::PrincipalRequestType:
53
                return new UserPrincipalRequest();
54
            case self::CalendarHomeRequestType:
55
                return new CalendarHomeRequest();
56
            case self::CalendarsRequestType:
57
                return new GetCalendarsRequest();
58
            case self::CalendarRequestType:
59
                return new GetCalendarRequest();
60
            case self::CalendarSyncRequestType:
61
                if(count($params) == 0 )
62
                    throw new \InvalidArgumentException();
63
                return new CalendarSyncRequest($params[0]);
64
            case self::CalendarMultiGetRequestType:
65
                if(count($params) == 0 )
66
                    throw new \InvalidArgumentException();
67
                return new CalendarMultiGetRequest($params[0]);
68
            case self::CalendarQueryRequestType:
69
                if(count($params) == 0 )
70
                    throw new \InvalidArgumentException();
71
                return new CalendarQueryRequest($params[0]);
72
            case self::CalendarCreateRequestType:
73
                if(count($params) == 0 )
74
                    throw new \InvalidArgumentException();
75
                return new CalendarCreateRequest($params[0]);
76
            case self::EventCreateRequestType:
77
                if(count($params) == 0 )
78
                    throw new \InvalidArgumentException();
79
                return new EventCreateRequest($params[0]);
80
            case self::EventUpdateRequestType:
81
                if(count($params) == 0 )
82
                    throw new \InvalidArgumentException();
83
                return new EventUpdateRequest($params[0]);
84
        }
85
        return null;
86
    }
87
}