Conditions | 12 |
Paths | 12 |
Total Lines | 39 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
67 | public function send() |
||
68 | { |
||
69 | $service = self::_getService($this->getOptions()); |
||
70 | |||
71 | $data = $this->getCustomProperties(); |
||
72 | $data['text'] = $this->getText(); |
||
73 | |||
74 | $message = new Zend_Mobile_Push_Message_Gcm(); |
||
75 | $message->addToken($this->getAddress()); |
||
76 | $message->setId($this->getId()); // TODO: GCM equivalent needed? |
||
77 | $message->setData($data); |
||
78 | |||
79 | try { |
||
80 | $response = $service->send($message); |
||
81 | } catch (Zend_Http_Client_Exception $e) { |
||
82 | throw new Tiqr_Message_Exception_SendFailure("HTTP client error", true, $e); |
||
83 | } catch (Zend_Mobile_Push_Exception_ServerUnavailable $e) { |
||
84 | throw new Tiqr_Message_Exception_SendFailure("Server unavailable", true, $e); |
||
85 | } catch (Zend_Mobile_Push_Exception_InvalidAuthToken $e) { |
||
86 | throw new Tiqr_Message_Exception_AuthFailure("Invalid token", $e); |
||
87 | } catch (Zend_Mobile_Push_Exception_InvalidPayload $e) { |
||
88 | throw new Tiqr_Message_Exception_SendFailure("Payload too large", $e); |
||
|
|||
89 | } catch (Zend_Mobile_Push_Exception $e) { |
||
90 | throw new Tiqr_Message_Exception_SendFailure("General send error", false, $e); |
||
91 | } |
||
92 | |||
93 | // handle errors, ignoring registration_id's |
||
94 | $error = null; |
||
95 | foreach ($response->getResults() as $k => $v) { |
||
96 | if (isset($v['error']) && $v['error'] === "MismatchSenderId") { |
||
97 | throw new Tiqr_Message_Exception_MismatchSenderId("MismatchSenderId", true); |
||
98 | } |
||
99 | if (isset($v['error']) && is_null($error)) { |
||
100 | $error = $v['error']; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | if ($error != null) { |
||
105 | throw new Tiqr_Message_Exception_SendFailure("Error in GCM response: " . $error, true); |
||
106 | } |
||
110 |