Issues (26)

src/Components/Line.php (3 issues)

1
<?php
2
3
namespace Raptor\Request\Components;
4
5
class Line
6
{
7
    /**
8
     * method
9
     * @see https://tools.ietf.org/html/rfc7231#section-4
10
     *
11
     * @var string
12
     */
13
    protected $method;
14
15
    /**
16
     * request-target
17
     * @see https://tools.ietf.org/html/rfc7230#section-5.3
18
     *
19
     * @var \Raptor\Request\Components\Target
20
     */
21
    protected $target;
22
23
    /**
24
     * HTTP-version
25
     *
26
     * @var string
27
     */
28
    protected $version;
29
30
    /**
31
     * Class constructor
32
     */
33
    public function __construct()
34
    {
35
        $this->target = new Target;
36
    }
37
38
    /**
39
     * Get the method.
40
     *
41
     * @return  string
42
     */
43
    public function method()
44
    {
45
        if ($this->method !== null) {
46
            return $this->method;
47
        }
48
        $this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
0 ignored issues
show
Documentation Bug introduced by
It seems like IssetNode ? $_SERVER['REQUEST_METHOD'] : false can also be of type false. However, the property $method is declared as type string. 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...
49
        if ($this->method === 'POST' && !empty($_SERVER['X-HTTP-METHOD-OVERRIDE'])) {
50
            return $this->method = strtoupper($_SERVER['X-HTTP-METHOD-OVERRIDE']);
51
        }
52
        if ($this->method === 'POST' && !empty($_POST['_method'])) {
53
            return $this->method = strtoupper($_POST['_method']);
54
        }
55
        return $this->method;
56
    }
57
58
    /**
59
     * Get the request-target.
60
     *
61
     * @return  \Raptor\Request\Components\Target
62
     */
63
    public function target()
64
    {
65
        return $this->target;
66
    }
67
68
    /**
69
     * Get the HTTP-version.
70
     *
71
     * @return  string
72
     */
73
    public function version()
74
    {
75
        if ($this->version !== null) {
76
            return $this->version;
77
        }
78
        return $this->version = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false;
0 ignored issues
show
Documentation Bug introduced by
It seems like IssetNode ? $_SERVER['SERVER_PROTOCOL'] : false can also be of type false. However, the property $version is declared as type string. 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...
Bug Best Practice introduced by
The expression return $this->version = ...RVER_PROTOCOL'] : false could also return false which is incompatible with the documented return type string. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
79
    }
80
}