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 ( fe47a8...0cf489 )
by Benjamin
02:41
created

Request   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 88.46%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 49
ccs 23
cts 26
cp 0.8846
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromGlobals() 0 14 2
A __construct() 0 21 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lib\Http;
6
7
use GuzzleHttp\Psr7\Request as BaseRequest;
8
use Psr\Http\Message\RequestInterface;
9
10
class Request extends BaseRequest
11
{
12
    const METHOD_HEAD = 'HEAD';
13
    const METHOD_GET = 'GET';
14
    const METHOD_POST = 'POST';
15
16
    protected $query;
17
    protected $request;
18
    protected $cookie;
19
    protected $server;
20
    protected $files;
21
22 4
    public function __construct(array $query = [], array $request = [], array $cookie = [], array $server = [], array $files = [])
23
    {
24 4
        $this->query = new ParamCollection($query);
25 4
        $this->request = new ParamCollection($request);
26 4
        $this->cookie = new ParamCollection($cookie);
27 4
        $this->server = new ServerCollection($server);
28 4
        $this->files = new ParamCollection($files);
29
30 4
        $method = $this->server->has('REQUEST_METHOD') ? $this->server->get('REQUEST_METHOD') : 'GET';
31
32 4
        $requestUri = '/';
33 4
        if ($this->server->has('REQUEST_URI')) {
34 1
            $requestUri = $this->server->get('REQUEST_URI');
35 3
        } elseif ($this->server->has('ORIG_PATH_INFO')) {
36
            $requestUri = $this->server->get('ORIG_PATH_INFO');
37
            $this->server->set('REQUEST_URI', $requestUri);
38
        }
39
40 4
        $version = $this->server->has('SERVER_PROTOCOL') ?? mb_substr($this->server->get('SERVER_PROTOCOL'), -3) ?? '1.1';
41
42 4
        parent::__construct($method, $requestUri, $this->server->getHeaders(), http_build_query($this->request->all()), $version);
43 4
    }
44
45 1
    public static function createFromGlobals(): RequestInterface
46
    {
47 1
        foreach ([$_GET, $_POST, $_COOKIE] as &$array) {
0 ignored issues
show
Bug introduced by
The expression array($_GET, $_POST, $_COOKIE) cannot be used as a reference.

Let?s assume that you have the following foreach statement:

foreach ($array as &$itemValue) { }

$itemValue is assigned by reference. This is possible because the expression (in the example $array) can be used as a reference target.

However, if we were to replace $array with something different like the result of a function call as in

foreach (getArray() as &$itemValue) { }

then assigning by reference is not possible anymore as there is no target that could be modified.

Available Fixes

1. Do not assign by reference
foreach (getArray() as $itemValue) { }
2. Assign to a local variable first
$array = getArray();
foreach ($array as &$itemValue) {}
3. Return a reference
function &getArray() { $array = array(); return $array; }

foreach (getArray() as &$itemValue) { }
Loading history...
48
            array_walk($array, function ($value) {
49
                htmlspecialchars($value);
50 1
            });
51
        }
52
53 1
        return new self(
54 1
            $_GET,
55 1
            $_POST,
56 1
            $_COOKIE,
57 1
            $_SERVER,
58 1
            $_FILES
59
        );
60
    }
61
}
62