Conditions | 13 |
Paths | 35 |
Total Lines | 71 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
29 | public function resolveListeners(Update $update): PromiseInterface |
||
30 | { |
||
31 | $deferred = new Deferred(); |
||
32 | $listeners = []; |
||
33 | $updateType = $update->getUpdateType(); |
||
34 | $this->mergeListenersByType($listeners, $updateType); |
||
35 | $this->mergeListenersByType($listeners, Update::class); |
||
36 | |||
37 | switch ($updateType) { |
||
38 | |||
39 | case CallbackQuery::class: |
||
40 | $callbackQuery = $update->getCallbackQuery(); |
||
41 | $text = $callbackQuery->getMessage() ? $callbackQuery->getMessage()->getText() : null; |
||
42 | if ($text) { |
||
43 | $this->findListenerAndPush($listeners, 'cb_query_texts', $text); |
||
44 | } |
||
45 | if ($callbackQuery->getData()) { |
||
46 | $this->findListenerAndPush($listeners, 'cb_query_data', $callbackQuery->getData()); |
||
47 | } |
||
48 | $chatId = $update->getEffectiveChat() ? $update->getEffectiveChat()->getId() : null; |
||
49 | if ($chatId) { |
||
|
|||
50 | $this->conversationManager->getConversationHandler($chatId) |
||
51 | ->then(function ($handler) use ($deferred, &$listeners) { |
||
52 | if ($handler) { |
||
53 | $listeners[] = new Listener($handler, $this->container); |
||
54 | } |
||
55 | $deferred->resolve($listeners); |
||
56 | }); |
||
57 | } else { |
||
58 | $deferred->resolve($listeners); |
||
59 | } |
||
60 | break; |
||
61 | |||
62 | case Message::class: |
||
63 | $text = $update->getMessage()->getText(); |
||
64 | if ($text) { |
||
65 | $chatId = $update->getEffectiveChat()->getId(); |
||
66 | $this->conversationManager->getConversationHandler($chatId) |
||
67 | ->then(function ($handlerInfo) use ($chatId, $text, $deferred, &$listeners) { |
||
68 | if (!$handlerInfo) { |
||
69 | $this->findListenerAndPush($listeners, 'messages', $text); |
||
70 | $deferred->resolve($listeners); |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | $skipListeners = $handlerInfo[1]; |
||
75 | if ($skipListeners) { |
||
76 | $listeners[] = new Listener($handlerInfo[0], $this->container); |
||
77 | } else { |
||
78 | $listener = $this->findListenerAndPush($listeners, 'messages', $text); |
||
79 | if (!$listener) { |
||
80 | $listeners[] = new Listener($handlerInfo[0], $this->container); |
||
81 | } else { |
||
82 | $this->conversationManager->deleteConversationCache($chatId); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | $deferred->resolve($listeners); |
||
87 | }); |
||
88 | |||
89 | } else { |
||
90 | $deferred->resolve($listeners); |
||
91 | } |
||
92 | break; |
||
93 | |||
94 | default: |
||
95 | $deferred->resolve($listeners); |
||
96 | |||
97 | } |
||
98 | |||
99 | return $deferred->promise(); |
||
100 | } |
||
133 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: