Issues (1)

src/Message/To.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kafkiansky\SmsRu\Message;
6
7
final class To extends Recipient
8
{
9
    /**
10
     * @var string
11
     */
12
    private $message;
13
14
    /**
15
     * @var array
16
     */
17
    private $tos;
18
19
    /**
20
     * @var bool
21
     */
22
    private $useIconv;
23
24
    /**
25
     * @param string|array $tos
26
     * @param string       $message
27
     * @param bool         $useIconv
28
     */
29
    public function __construct($tos, string $message, bool $useIconv = false)
30
    {
31
        $this->message = $message;
32
        $this->tos = $tos;
0 ignored issues
show
Documentation Bug introduced by
It seems like $tos can also be of type string. However, the property $tos 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...
33
        $this->useIconv = $useIconv;
34
    }
35
36
    /**
37
     * @return array|string
38
     */
39
    public function getTo()
40
    {
41
        return $this->tos;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getMessage(): string
48
    {
49
        return $this->message;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function useIconv(): bool
56
    {
57
        return $this->useIconv;
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function asMulti(): bool
64
    {
65
        return false;
66
    }
67
}
68