Issues (3627)

Swiftmailer/SendGrid/Callback/ResponseItem.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\EmailBundle\Swiftmailer\SendGrid\Callback;
13
14
use Mautic\EmailBundle\Swiftmailer\SendGrid\Exception\ResponseItemException;
15
16
class ResponseItem
17
{
18
    /**
19
     * @var string
20
     */
21
    private $email;
22
23
    /**
24
     * @var string
25
     */
26
    private $reason;
27
28
    /**
29
     * @var int
30
     */
31
    private $dncReason;
32
33
    /**
34
     * @throws ResponseItemException
35
     */
36
    public function __construct(array $item)
37
    {
38
        if (empty($item['email'])) {
39
            throw new ResponseItemException();
40
        }
41
        $this->email     = $item['email'];
42
        $this->reason    = !empty($item['reason']) ? $item['reason'] : null;
43
        $this->dncReason = CallbackEnum::convertEventToDncReason($item['event']);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mautic\EmailBundle\Swift...cReason($item['event']) can also be of type string. However, the property $dncReason is declared as type integer. 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...
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getEmail()
50
    {
51
        return $this->email;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getReason()
58
    {
59
        return $this->reason;
60
    }
61
62
    /**
63
     * @return int
64
     */
65
    public function getDncReason()
66
    {
67
        return $this->dncReason;
68
    }
69
}
70