Conditions | 13 |
Paths | 35 |
Total Lines | 45 |
Code Lines | 34 |
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 |
||
59 | public function send(NetGsmMessage $message): void |
||
60 | { |
||
61 | if (empty($message->recipients)) { |
||
62 | throw CouldNotSendNotification::emptyRecipients(); |
||
63 | } |
||
64 | |||
65 | $msg = |
||
66 | "<?xml version='1.0' encoding='utf-8'?>". |
||
67 | '<mainbody>'. |
||
68 | $this->prepareHeader($message). |
||
69 | $this->prepareBody($message). |
||
70 | '</mainbody>'; |
||
71 | |||
72 | try { |
||
73 | $response = $this->client->post(self::URI, [ |
||
74 | 'body' => $msg, |
||
75 | 'headers' => [ |
||
76 | 'Content-Type', 'text/xml; charset=utf-8', |
||
77 | ], |
||
78 | ]); |
||
79 | $result = explode(' ', $response->getBody()->getContents()); |
||
80 | |||
81 | if (! isset($result[0])) { |
||
82 | throw CouldNotSendNotification::invalidResponse(); |
||
83 | } |
||
84 | |||
85 | if ($result[0] === '00' || $result[0] === '01' || $result[0] === '02') { |
||
86 | return $result[1]; |
||
87 | } elseif ($result[0] === '20') { |
||
88 | throw CouldNotSendNotification::invalidMessageContent(); |
||
89 | } elseif ($result[0] === '30') { |
||
90 | throw InvalidConfiguration::invalidCredentials(); |
||
91 | } elseif ($result[0] === '40') { |
||
92 | throw CouldNotSendNotification::invalidHeader(); |
||
93 | } elseif ($result[0] === '70') { |
||
94 | throw CouldNotSendNotification::invalidRequest(); |
||
95 | } else { |
||
96 | throw CouldNotSendNotification::unknownError(); |
||
97 | } |
||
98 | } catch (InvalidConfiguration $exception) { |
||
99 | throw $exception; |
||
100 | } catch (CouldNotSendNotification $exception) { |
||
101 | throw $exception; |
||
102 | } catch (Exception $exception) { |
||
103 | throw CouldNotSendNotification::serviceRespondedWithAnError($exception); |
||
104 | } |
||
141 |