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