Issues (22)

lib/ApiResponse.php (1 issue)

1
<?php
2
3
namespace bSecure;
4
5
/**
6
 * Class ApiResponse.
7
 */
8
class ApiResponse
9
{
10
    /**
11
     * @var null|array
12
     */
13
    public $body;
14
15
    /**
16
     * @var int
17
     */
18
    public $status;
19
20
    /**
21
     * @var null|array
22
     */
23
    public $message;
24
25
    /**
26
     * @var null|array
27
     */
28
    public $exception;
29
30
    /**
31
     * @param null|array|string $body
32
     * @param int $status
33
     * @param null|array $message
34
     * @param null|array $exception
35
     */
36
    public function __construct( $body, $status, $message, $exception)
37
    {
38
        $this->body = $body;
0 ignored issues
show
Documentation Bug introduced by
It seems like $body can also be of type string. However, the property $body is declared as type array|null. 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...
39
        $this->status = $status;
40
        $this->message = $message;
41
        $this->exception = $exception;
42
    }
43
}