Request::getPostVars()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MarcolaMr\Router;
4
5
class Request
6
{
7
    /** @var string */
8
    private string $httpMethod;
9
10
    /** @var string */
11
    private string $uri;
12
13
    /** @var array */
14
    private array $queryParams = [];
15
16
    /** @var array */
17
    private array $postVars = [];
18
19
    /** @var array */
20
    private array $headers = [];
21
22
    /**
23
     * Construtor da classe
24
     */
25
    public function __construct()
26
    {
27
        $this->queryParams = $_GET ?? [];
28
        $this->postVars = $_POST ?? [];
29
        $this->headers = getallheaders();
0 ignored issues
show
Documentation Bug introduced by
It seems like getallheaders() can also be of type true. However, the property $headers is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
30
        $this->httpMethod = $_SERVER["REQUEST_METHOD"] ?? "";
31
        $this->uri = $_SERVER["REQUEST_URI"] ?? "";
32
    }
33
34
    /**
35
     * Método responsável por retornar o método HTTP da requisição
36
     * @return string
37
     */
38
    public function getHttpMethod(): string
39
    {
40
        return $this->httpMethod;
41
    }
42
43
    /**
44
     * Método responsável por retornar a URI da requisição
45
     * @return string
46
     */
47
    public function getUri(): string
48
    {
49
        return $this->uri;
50
    }
51
52
    /**
53
     * Método responsável por retornar os headers da requisição
54
     * @return array
55
     */
56
    public function getHeaders(): array
57
    {
58
        return $this->headers;
59
    }
60
61
    /**
62
     * Método responsável por retornar os parâmetros da url
63
     * @return array
64
     */
65
    public function getQueryParams(): array
66
    {
67
        return $this->queryParams;
68
    }
69
70
    /**
71
     * Método responsável por retornar as variáveis post
72
     * @return array
73
     */
74
    public function getPostVars(): array
75
    {
76
        return $this->postVars;
77
    }
78
}
79