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 ( 4e2c99...1d9319 )
by Gjero
02:21
created

Request::stripSlashesIfMagicQuotes()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 8
nop 2
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * Pimf
4
 *
5
 * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
6
 * @license   http://opensource.org/licenses/MIT MIT
7
 */
8
namespace Pimf;
9
10
/**
11
 * Request Manager - for controlled access to the global state of the world.
12
 *
13
 * @package Pimf
14
 * @author  Gjero Krsteski <[email protected]>
15
 */
16
class Request
17
{
18
    /**
19
     * @var Param
20
     */
21
    public static $postData;
22
23
    /**
24
     * @var Param
25
     */
26
    public static $getData;
27
28
    /**
29
     * @var Param
30
     */
31
    public static $cookieData;
32
33
    /**
34
     * @var Param
35
     */
36
    public static $cliData;
37
38
    /**
39
     * @var Util\Uploaded
40
     */
41
    public static $filesData;
42
43
    /**
44
     * @var Environment
45
     */
46
    public $env;
47
48
    /**
49
     * The request HTTP method send by the client-browser.
50
     *
51
     * @var null|string
52
     */
53
    protected $method = null;
54
55
    /**
56
     * @param array             $getData
57
     * @param array             $postData
58
     * @param array             $cookieData
59
     * @param array             $cliData
60
     * @param array             $filesData
61
     * @param \Pimf\Environment $env
62
     */
63
    public function __construct(
64
        array $getData,
65
        array $postData = array(),
66
        array $cookieData = array(),
67
        array $cliData = array(),
68
        array $filesData = array(),
69
        \Pimf\Environment $env
70
    ) {
71
72
        static::$getData = new Param($getData);
73
        static::$postData = new Param($postData);
74
        static::$cookieData = new Param($cookieData);
75
        static::$cliData = new Param($cliData);
76
        static::$filesData = Util\Uploaded\Factory::get($filesData);
77
78
        $this->env    = $env;
79
        $this->method = '' . strtoupper($env->REQUEST_METHOD);
80
    }
81
82
    /**
83
     * For fetching body/params sent via PUT|DELETE|PATCH Http method.
84
     *
85
     * @param bool $asResource
86
     *
87
     * @return Param|resource|boolean
88
     */
89
    public function streamInput($asResource = false)
90
    {
91
        if (0 === strpos($this->env->getRequestHeader('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
92
            && in_array($this->env->data()->get('REQUEST_METHOD', 'GET'), array('PUT', 'DELETE', 'PATCH'))
93
        ) {
94
95
            if ($asResource === true) {
96
                return $this->getContent($asResource);
97
            }
98
99
            $body = array();
100
            parse_str($this->getContent(), $body);
101
102
            return new Param($body);
0 ignored issues
show
Bug introduced by
It seems like $body can also be of type null; however, Pimf\Param::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
103
        }
104
105
        return false;
106
    }
107
108
    /**
109
     * HTTP GET variables.
110
     *
111
     * @return Param
112
     */
113
    public function fromGet()
114
    {
115
        return static::$getData;
116
    }
117
118
    /**
119
     * CLI arguments passed to script.
120
     *
121
     * @return Param
122
     */
123
    public function fromCli()
124
    {
125
        return static::$cliData;
126
    }
127
128
    /**
129
     * HTTP POST variables.
130
     *
131
     * @return Param
132
     */
133
    public function fromPost()
134
    {
135
        return static::$postData;
136
    }
137
138
    /**
139
     * HTTP Cookies.
140
     *
141
     * @return Param
142
     */
143
    public function fromCookie()
144
    {
145
        return static::$cookieData;
146
    }
147
148
    /**
149
     * Strip slashes from string or array
150
     *
151
     * @param $rawData
152
     *
153
     * @return array|string
154
     */
155
    public static function stripSlashes($rawData)
156
    {
157
        return is_array($rawData)
158
            ? array_map(
159
                function ($value) {
160
                    return \Pimf\Request::stripSlashes($value);
161
                },
162
                $rawData
163
            )
164
            : stripslashes($rawData);
165
    }
166
167
    /**
168
     * @param bool $asResource
169
     *
170
     * @return resource|string
171
     * @throws \LogicException When using the resource twice times.
172
     */
173
    public function getContent($asResource = false)
174
    {
175
        static $content;
176
177
        if (false === $content || (true === $asResource && null !== $content)) {
178
            throw new \LogicException('resource can only be returned once');
179
        }
180
181
        if (true === $asResource) {
182
            $content = false;
183
184
            return fopen('php://input', 'rb');
185
        }
186
187
        if (null === $content) {
188
            $content = file_get_contents('php://input');
189
        }
190
191
        return $content;
192
    }
193
194
    /**
195
     * The request method send by the client-browser.
196
     *
197
     * @return null|string
198
     */
199
    public function getMethod()
200
    {
201
        return $this->method;
202
    }
203
}
204