1 | <?php |
||
2 | |||
3 | namespace Andreshg112\PusherApiNotifications; |
||
4 | |||
5 | class PusherApiMessage |
||
6 | { |
||
7 | /** @var string */ |
||
8 | protected $channels = null; |
||
9 | |||
10 | /** @var string */ |
||
11 | protected $event = null; |
||
12 | |||
13 | /** @var array|string */ |
||
14 | protected $data = null; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $socketId = null; |
||
18 | |||
19 | /** @var bool */ |
||
20 | protected $debug = false; |
||
21 | |||
22 | /** @var bool */ |
||
23 | protected $alreadyEncoded = false; |
||
24 | |||
25 | /** |
||
26 | * Creates the instance. |
||
27 | * |
||
28 | * @param array|string $channels |
||
29 | * @param string $event |
||
30 | * @param mixed $data |
||
31 | * @param string|null $socketId |
||
32 | * @param bool $debug |
||
33 | * @param bool $alreadyEncoded |
||
34 | */ |
||
35 | 4 | public function __construct( |
|
36 | $channels = null, |
||
37 | $event = null, |
||
38 | $data = null, |
||
39 | $socketId = null, |
||
40 | $debug = false, |
||
41 | $alreadyEncoded = false |
||
42 | ) { |
||
43 | 4 | $this->channels = $channels; |
|
0 ignored issues
–
show
|
|||
44 | 4 | $this->event = $event; |
|
45 | 4 | $this->data = $data; |
|
46 | 4 | $this->socketId = $socketId; |
|
47 | 4 | $this->debug = $debug; |
|
48 | 4 | $this->alreadyEncoded = $alreadyEncoded; |
|
49 | 4 | } |
|
50 | |||
51 | /** |
||
52 | * A channel name or an array of channel names to publish the event on. |
||
53 | * |
||
54 | * @param array|string $channels |
||
55 | * @return $this |
||
56 | */ |
||
57 | 1 | public function channels($channels) |
|
58 | { |
||
59 | 1 | $this->channels = $channels; |
|
0 ignored issues
–
show
It seems like
$channels can also be of type array . However, the property $channels 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 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;
}
![]() |
|||
60 | |||
61 | 1 | return $this; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Pusher event. |
||
66 | * |
||
67 | * @param string $event |
||
68 | * @return $this |
||
69 | */ |
||
70 | 1 | public function event($event) |
|
71 | { |
||
72 | 1 | $this->event = $event; |
|
73 | |||
74 | 1 | return $this; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * Event data. |
||
79 | * |
||
80 | * @param mixed $data |
||
81 | * @return $this |
||
82 | */ |
||
83 | 1 | public function data($data) |
|
84 | { |
||
85 | 1 | $this->data = $data; |
|
86 | |||
87 | 1 | return $this; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * [optional]. |
||
92 | * |
||
93 | * @param string|null $socketId |
||
94 | * @return $this |
||
95 | */ |
||
96 | 1 | public function socketId($socketId = null) |
|
97 | { |
||
98 | 1 | $this->socketId = $socketId; |
|
99 | |||
100 | 1 | return $this; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * [optional]. |
||
105 | * |
||
106 | * @param bool $debug |
||
107 | * @return $this |
||
108 | */ |
||
109 | 1 | public function debug($debug = false) |
|
110 | { |
||
111 | 1 | $this->debug = $debug; |
|
112 | |||
113 | 1 | return $this; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * [optional]. |
||
118 | * |
||
119 | * @param bool $alreadyEncoded |
||
120 | * @return $this |
||
121 | */ |
||
122 | 1 | public function alreadyEncoded($alreadyEncoded = false) |
|
123 | { |
||
124 | 1 | $this->alreadyEncoded = $alreadyEncoded; |
|
125 | |||
126 | 1 | return $this; |
|
127 | } |
||
128 | |||
129 | 4 | public function toArray() |
|
130 | { |
||
131 | return [ |
||
132 | 4 | 'channels' => $this->channels, |
|
133 | 4 | 'event' => $this->event, |
|
134 | 4 | 'data' => $this->data, |
|
135 | 4 | 'socketId' => $this->socketId, |
|
136 | 4 | 'debug' => $this->debug, |
|
137 | 4 | 'alreadyEncoded' => $this->alreadyEncoded, |
|
138 | ]; |
||
139 | } |
||
140 | } |
||
141 |
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 theid
property of an instance of theAccount
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.