|
7 | 7 | use Longman\TelegramBot\Entities\Update; |
8 | 8 | use Longman\TelegramBot\Entities\User; |
9 | 9 |
|
10 | | -/** |
11 | | - * @method getUpdate(): Update |
12 | | - */ |
13 | 10 | trait UsesEffectiveEntities |
14 | 11 | { |
15 | 12 |
|
16 | | - protected function getEffectiveUser(): ?User |
| 13 | + protected function getEffectiveUser(Update $update): ?User |
17 | 14 | { |
18 | | - if (! method_exists($this, 'getUpdate')) { |
19 | | - return null; |
20 | | - } |
21 | | - |
22 | | - $update = $this->getUpdate(); |
23 | | - |
24 | | - if (! $update instanceof Update) { |
25 | | - return null; |
26 | | - } |
27 | | - |
28 | | - $data = $update->getRawData(); |
29 | 15 | $type = $update->getUpdateType(); |
30 | 16 |
|
31 | | - $user = $data[$type]['from'] |
32 | | - ?? $data['poll_answer']['user'] |
| 17 | + $user = $update->$type['from'] |
| 18 | + ?? $update->poll_answer['user'] |
33 | 19 | ?? null; |
34 | 20 |
|
35 | 21 | return $user ? new User($user) : null; |
36 | 22 | } |
37 | 23 |
|
38 | | - protected function getEffectiveChat(): ?Chat |
| 24 | + protected function getEffectiveChat(Update $update): ?Chat |
39 | 25 | { |
40 | | - if (! method_exists($this, 'getUpdate')) { |
41 | | - return null; |
42 | | - } |
43 | | - |
44 | | - $update = $this->getUpdate(); |
45 | | - |
46 | | - if (! $update instanceof Update) { |
47 | | - return null; |
48 | | - } |
49 | | - |
50 | | - $data = $update->getRawData(); |
51 | 26 | $type = $update->getUpdateType(); |
52 | 27 |
|
53 | | - $chat = $data[$type]['chat'] |
54 | | - ?? $data['callback_query']['message']['chat'] |
| 28 | + $chat = $update->$type['chat'] |
| 29 | + ?? $update->callback_query['message']['chat'] |
55 | 30 | ?? null; |
56 | 31 |
|
57 | 32 | return $chat ? new Chat($chat) : null; |
58 | 33 | } |
59 | 34 |
|
60 | | - protected function getEffectiveMessage(): ?Message |
| 35 | + protected function getEffectiveMessage(Update $update): ?Message |
61 | 36 | { |
62 | | - if (! method_exists($this, 'getUpdate')) { |
63 | | - return null; |
64 | | - } |
65 | | - |
66 | | - $update = $this->getUpdate(); |
67 | | - |
68 | | - if (! $update instanceof Update) { |
69 | | - return null; |
70 | | - } |
71 | | - |
72 | | - $data = $update->getRawData(); |
73 | | - $message = $data['edited_channel_post'] |
74 | | - ?? $data['channel_post'] |
75 | | - ?? $data['callback_query']['message'] |
76 | | - ?? $data['edited_message'] |
77 | | - ?? $data['message'] |
| 37 | + $message = $update->edited_channel_post |
| 38 | + ?? $update->channel_post |
| 39 | + ?? $update->callback_query['message'] |
| 40 | + ?? $update->edited_message |
| 41 | + ?? $update->message |
78 | 42 | ?? null; |
79 | 43 |
|
80 | 44 | return $message ? new Message($message) : null; |
|
0 commit comments