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.
Completed
Push — master ( 485009...781b01 )
by François
02:47
created

Request::getRequestMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
namespace SURFnet\VPN\Server\Api;
19
20
use SURFnet\VPN\Server\Api\Exception\HttpException;
21
22
class Request
23
{
24
    public function __construct(array $serverData, array $getData, array $postData)
25
    {
26
        $this->serverData = $serverData;
0 ignored issues
show
Bug introduced by
The property serverData does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
        $this->getData = $getData;
0 ignored issues
show
Bug introduced by
The property getData does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
        $this->postData = $postData;
0 ignored issues
show
Bug introduced by
The property postData does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
    }
30
31
    public function getRequestMethod()
32
    {
33
        return $this->serverData['REQUEST_METHOD'];
34
    }
35
36
    public function getServerName()
37
    {
38
        return $this->serverData['SERVER_NAME'];
39
    }
40
41
    public function getPathInfo()
42
    {
43
        if (!array_key_exists('PATH_INFO', $this->serverData)) {
44
            return '/';
45
        }
46
47
        return $this->serverData['PATH_INFO'];
48
    }
49
50
    public function getUrl()
51
    {
52
        // deal with non-standard port
53
        // deal with non-existing request_scheme
54
        return sprintf(
55
            '%s://%s%s',
56
            $this->serverData['REQUEST_SCHEME'],
57
            $this->serverData['SERVER_NAME'],
58
            $this->serverData['REQUEST_URI']
59
        );
60
    }
61
62 View Code Duplication
    public function getQueryParameter($key, $defaultValue = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        if (array_key_exists($key, $this->getData)) {
65
            return $this->getData[$key];
66
        }
67
68
        if (is_null($defaultValue)) {
69
            throw new HttpException(
70
                sprintf('missing query parameter "%s"', $key),
71
                400
72
            );
73
        }
74
75
        return $defaultValue;
76
    }
77
78 View Code Duplication
    public function getHeader($key, $defaultValue = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        // do some header key normalization
81
        if (array_key_exists($key, $this->serverData)) {
82
            return $this->serverData[$key];
83
        }
84
85
        if (is_null($defaultValue)) {
86
            throw new HttpException(
87
                sprintf('missing header "%s"', $key),
88
                400
89
            );
90
        }
91
92
        return $defaultValue;
93
    }
94
95 View Code Duplication
    public function getPostParameter($key, $defaultValue = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        if (array_key_exists($key, $this->postData)) {
98
            return $this->postData[$key];
99
        }
100
101
        if (is_null($defaultValue)) {
102
            throw new HttpException(
103
                sprintf('missing post parameter "%s"', $key),
104
                400
105
            );
106
        }
107
108
        return $defaultValue;
109
    }
110
}
111