Issues (62)

Security/Http/RequestContext.php (2 issues)

1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Security\Http;
12
13
/**
14
 * @author Yaroslav Honcharuk <[email protected]>
15
 */
16
class RequestContext
17
{
18
    /**
19
     * @var string
20
     */
21
    private $pathInfo;
22
23
    /**
24
     * @var string
25
     */
26
    private $host;
27
28
    /**
29
     * @var string
30
     */
31
    private $method;
32
33
    /**
34
     * @var string
35
     */
36
    private $clientIp;
37
38
    /**
39
     * @param string|\Closure|null $pathInfo
40
     * @param string|\Closure|null $host
41
     * @param string|null          $method
42
     * @param string|null          $clientIp
43
     */
44 17
    public function __construct($pathInfo = null, $host = null, $method = null, $clientIp = null)
45
    {
46 17
        $this->pathInfo = $pathInfo;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pathInfo can also be of type Closure. However, the property $pathInfo 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...
47 17
        $this->host = $host;
0 ignored issues
show
Documentation Bug introduced by
It seems like $host can also be of type Closure. However, the property $host 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...
48 17
        $this->method = $method;
49 17
        $this->clientIp = $clientIp;
50 17
    }
51
52
    /**
53
     * @return string
54
     */
55 11
    public function getPathInfo()
56
    {
57 11
        if ($this->pathInfo instanceof \Closure) {
58 9
            $this->pathInfo = $this->pathInfo->__invoke();
59
        }
60
61 11
        return $this->pathInfo;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 5
    public function getHost()
68
    {
69 5
        if ($this->host instanceof \Closure) {
70 3
            $this->host = $this->host->__invoke();
71
        }
72
73 5
        return $this->host;
74
    }
75
76
    /**
77
     * @return string
78
     */
79 3
    public function getMethod()
80
    {
81 3
        return $this->method;
82
    }
83
84
    /**
85
     * @return string
86
     */
87 3
    public function getClientIp()
88
    {
89 3
        return $this->clientIp;
90
    }
91
}
92