| Conditions | 6 |
| Paths | 32 |
| Total Lines | 56 |
| Code Lines | 38 |
| 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 |
||
| 104 | public function buildPushMessage(ApnsReceiver $receiver, Notification $notification) |
||
| 105 | { |
||
| 106 | $message = $notification->getMessage(); |
||
| 107 | |||
| 108 | $messageId = sha1( |
||
| 109 | sprintf( |
||
| 110 | '%s%s%s%s', |
||
| 111 | $receiver->getToken(), |
||
| 112 | $message->getParameter(Message::PARAMETER_TITLE), |
||
| 113 | $message->getParameter(Message::PARAMETER_BODY), |
||
| 114 | time() |
||
| 115 | ) |
||
| 116 | ); |
||
| 117 | $badge = $notification->getParameter(Notification::PARAMETER_BADGE) === null |
||
| 118 | ? null |
||
| 119 | : (int) $notification->getParameter(Notification::PARAMETER_BADGE); |
||
| 120 | |||
| 121 | $pushMessage = (new ServiceMessage) |
||
| 122 | ->setId($messageId) |
||
| 123 | ->setToken($receiver->getToken()) |
||
| 124 | ->setBadge($badge) |
||
| 125 | ->setSound($notification->getParameter(Notification::PARAMETER_SOUND)) |
||
| 126 | ->setCategory($notification->getParameter(Notification::PARAMETER_CATEGORY)) |
||
| 127 | ->setCustom($message->getPayloadData()); |
||
| 128 | |||
| 129 | if ($notification->getParameter(Notification::PARAMETER_CONTENT_AVAILABLE) !== null) { |
||
| 130 | $pushMessage->setContentAvailable( |
||
| 131 | (int) $notification->getParameter(Notification::PARAMETER_CONTENT_AVAILABLE) |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | |||
| 135 | if (is_array($notification->getParameter(Notification::PARAMETER_URL_ARGS))) { |
||
| 136 | $pushMessage->setUrlArgs($notification->getParameter(Notification::PARAMETER_URL_ARGS)); |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($notification->getParameter(Notification::PARAMETER_TTL) !== null) { |
||
| 140 | $expire = time() + (int) $notification->getParameter(Notification::PARAMETER_TTL); |
||
| 141 | |||
| 142 | $pushMessage->setExpire($expire); |
||
| 143 | } |
||
| 144 | |||
| 145 | if ($this->shouldAddNotification($message)) { |
||
| 146 | $pushMessage->setAlert(new ServiceMessageAlert( |
||
| 147 | $message->getParameter(Message::PARAMETER_BODY), |
||
| 148 | $message->getParameter(Message::PARAMETER_ACTION_LOC_KEY), |
||
| 149 | $message->getParameter(Message::PARAMETER_BODY_LOC_KEY), |
||
| 150 | $message->getParameter(Message::PARAMETER_BODY_LOC_ARGS), |
||
| 151 | $message->getParameter(Message::PARAMETER_LAUNCH_IMAGE), |
||
| 152 | $message->getParameter(Message::PARAMETER_TITLE), |
||
| 153 | $message->getParameter(Message::PARAMETER_TITLE_LOC_KEY), |
||
| 154 | $message->getParameter(Message::PARAMETER_TITLE_LOC_ARGS) |
||
| 155 | )); |
||
| 156 | } |
||
| 157 | |||
| 158 | return $pushMessage; |
||
| 159 | } |
||
| 160 | |||
| 183 |