| Conditions | 2 |
| Paths | 2 |
| Total Lines | 120 |
| Code Lines | 104 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 3 | 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 |
||
| 112 | public static function getPostDataWithoutSignature($newApi) |
||
| 113 | { |
||
| 114 | if($newApi){ |
||
| 115 | $timestamp = time(); |
||
| 116 | $data = array( |
||
| 117 | 'signature' => array ( |
||
| 118 | 'timestamp' => $timestamp, |
||
| 119 | 'token' => '50dcec4a2d0ef27036c44ebd9ce9324736fc98ef9405428803', |
||
| 120 | ), |
||
| 121 | 'event-data' => |
||
| 122 | array( |
||
| 123 | 'tags' => |
||
| 124 | array( |
||
| 125 | 0 => 'my_tag_1', |
||
| 126 | 1 => 'my_tag_2' |
||
| 127 | ), |
||
| 128 | 'timestamp' => $timestamp, |
||
| 129 | 'storage' => |
||
| 130 | array( |
||
| 131 | 'url' => 'https://se.api.mailgun.net/v3/domains/acme.com/messages/message_key', |
||
| 132 | 'key' => 'message_key', |
||
| 133 | ), |
||
| 134 | 'envelope' => |
||
| 135 | array( |
||
| 136 | 'transport' => 'smtp', |
||
| 137 | 'sender' => '[email protected]', |
||
| 138 | 'sending-ip' => '209.61.154.250', |
||
| 139 | 'targets' => '[email protected]', |
||
| 140 | ), |
||
| 141 | 'recipient-domain' => 'example.com', |
||
| 142 | 'event' => 'delivered', |
||
| 143 | 'campaigns' => |
||
| 144 | array(), |
||
| 145 | 'user-variables' => |
||
| 146 | array( |
||
| 147 | 'my_var_1' => 'Mailgun Variable #1', |
||
| 148 | 'my-var-2' => 'awesome', |
||
| 149 | ), |
||
| 150 | 'flags' => |
||
| 151 | array('is-routed' => false, 'is-authenticated' => true, 'is-system-test' => false, 'is-test-mode' => false, |
||
| 152 | ), |
||
| 153 | 'log-level' => 'info', |
||
| 154 | 'message' => |
||
| 155 | array( |
||
| 156 | 'headers' => |
||
| 157 | array( |
||
| 158 | 'to' => 'Alice <[email protected]>', |
||
| 159 | 'message-id' => '[email protected]', |
||
| 160 | 'from' => 'Bob <[email protected]>', |
||
| 161 | 'subject' => 'Test delivered webhook', |
||
| 162 | ), |
||
| 163 | 'attachments' => array(), |
||
| 164 | 'size' => 111, |
||
| 165 | ), |
||
| 166 | 'recipient' => '[email protected]', |
||
| 167 | 'id' => 'CPgfbmQMTCKtHW6uIWtuVe', |
||
| 168 | 'delivery-status' => |
||
| 169 | array( |
||
| 170 | 'tls' => true, |
||
| 171 | 'mx-host' => 'smtp-in.example.com', |
||
| 172 | 'attempt-no' => 1, |
||
| 173 | 'description' => '', |
||
| 174 | 'session-seconds' => 0.4331989288330078, |
||
| 175 | 'utf8' => true, |
||
| 176 | 'code' => 250, |
||
| 177 | 'message' => 'OK', |
||
| 178 | 'certificate-verified' => true, |
||
| 179 | ), |
||
| 180 | ), |
||
| 181 | ); |
||
| 182 | } else { |
||
| 183 | $data = array( |
||
| 184 | 'event' => 'delivered', |
||
| 185 | 'domain' => 'acme', |
||
| 186 | 'timestamp' => time(), |
||
| 187 | 'token' => 'c47468e81de0818af77f3e14a728602a29', |
||
| 188 | 'X-Mailgun-Sid' => 'irrelevant', |
||
| 189 | 'attachment-count' => 'irrelevant', |
||
| 190 | 'recipient' => '[email protected]', |
||
| 191 | 'message-headers' => json_encode(array( |
||
| 192 | array('X-Mailgun-Sending-Ip', '198.62.234.37'), |
||
| 193 | array('X-Mailgun-Sid', 'WyIwN2U4YyIsICJzdXBwb3J0QGF6aW5lLm1lIiwgIjA2MjkzIl0='), |
||
| 194 | array('Received', 'from acme.test (b4.cme.test [194.140.238.63])'), |
||
| 195 | array('Sender', '[email protected]'), |
||
| 196 | array('Message-Id', '<[email protected]>'), |
||
| 197 | array('Date', 'Mon, 07 Sep 2020 14:38:41 +0200'), |
||
| 198 | array('Subject', 'Some email message subject'), |
||
| 199 | array('From', '\'acme.test sender-name\' <[email protected]>'), |
||
| 200 | array('To', '\'acme.test recipient-name\' <[email protected]>'), |
||
| 201 | array('Mime-Version', '1.0'), |
||
| 202 | array('Content-Transfer-Encoding', '[\'quoted-printable\']') |
||
| 203 | )), |
||
| 204 | 'Message-Id' => '<[email protected]>', |
||
| 205 | 'description' => 'some description', |
||
| 206 | 'notification' => 'some notification', |
||
| 207 | 'reason' => 'don\'t know the reason', |
||
| 208 | 'code' => 123, |
||
| 209 | 'ip' => '42.42.42.42', |
||
| 210 | 'error' => 'some error', |
||
| 211 | 'country' => 'CH', |
||
| 212 | 'city' => 'Zurich', |
||
| 213 | 'region' => '8000', |
||
| 214 | 'campaign-id' => '2014-01-01', |
||
| 215 | 'campaign-name' => 'newsletter', |
||
| 216 | 'client-name' => 'some client', |
||
| 217 | 'client-os' => 'some os', |
||
| 218 | 'client-type' => 'some type', |
||
| 219 | 'device-type' => 'some device', |
||
| 220 | 'mailing-list' => 'no list', |
||
| 221 | 'tag' => 'hmmm no tag', |
||
| 222 | 'user-agent' => 'Firefox 42', |
||
| 223 | 'url' => '', |
||
| 224 | 'duplicate-key' => 'data1', |
||
| 225 | 'Duplicate-key' => 'data2', |
||
| 226 | 'some-custom-var1' => 'some data1', |
||
| 227 | 'some-custom-var2' => 'some data2', |
||
| 228 | 'some-custom-var3' => 'some data3', |
||
| 229 | ); |
||
| 230 | } |
||
| 231 | return $data; |
||
| 232 | } |
||
| 234 |