Complex classes like ChangesSubscriptionSender often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ChangesSubscriptionSender, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class ChangesSubscriptionSender extends SubscriptionSender |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Send digest and list subscriptions |
||
| 17 | * |
||
| 18 | * This sends mails to all subscribers that have a subscription for namespaces above |
||
| 19 | * the given page if the needed $conf['subscribe_time'] has passed already. |
||
| 20 | * |
||
| 21 | * This function is called form lib/exe/indexer.php |
||
| 22 | * |
||
| 23 | * @param string $page |
||
| 24 | * |
||
| 25 | * @return int number of sent mails |
||
| 26 | */ |
||
| 27 | public function sendBulk($page) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Send the diff for some page change |
||
| 135 | * |
||
| 136 | * @param string $subscriber_mail The target mail address |
||
| 137 | * @param string $template Mail template ('subscr_digest', 'subscr_single', 'mailtext', ...) |
||
| 138 | * @param string $id Page for which the notification is |
||
| 139 | * @param int|null $rev Old revision if any |
||
| 140 | * @param string $summary Change summary if any |
||
| 141 | * |
||
| 142 | * @return bool true if successfully sent |
||
| 143 | */ |
||
| 144 | public function sendPageDiff($subscriber_mail, $template, $id, $rev = null, $summary = '') |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Send the diff for some media change |
||
| 208 | * |
||
| 209 | * @fixme this should embed thumbnails of images in HTML version |
||
| 210 | * |
||
| 211 | * @param string $subscriber_mail The target mail address |
||
| 212 | * @param string $template Mail template ('uploadmail', ...) |
||
| 213 | * @param string $id Media file for which the notification is |
||
| 214 | * @param int|bool $rev Old revision if any |
||
| 215 | */ |
||
| 216 | public function sendMediaDiff($subscriber_mail, $template, $id, $rev = false) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Get a valid message id for a certain $id and revision (or the current revision) |
||
| 245 | * |
||
| 246 | * @param string $id The id of the page (or media file) the message id should be for |
||
| 247 | * @param string $rev The revision of the page, set to the current revision of the page $id if not set |
||
| 248 | * |
||
| 249 | * @return string |
||
| 250 | */ |
||
| 251 | protected function getMessageID($id, $rev = null) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Lock subscription info |
||
| 270 | * |
||
| 271 | * We don't use io_lock() her because we do not wait for the lock and use a larger stale time |
||
| 272 | * |
||
| 273 | * @param string $id The target page or namespace, specified by id; Namespaces |
||
| 274 | * are identified by appending a colon. |
||
| 275 | * |
||
| 276 | * @return bool true, if you got a succesful lock |
||
| 277 | * @author Adrian Lang <[email protected]> |
||
| 278 | */ |
||
| 279 | protected function lock($id) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Unlock subscription info |
||
| 303 | * |
||
| 304 | * @param string $id The target page or namespace, specified by id; Namespaces |
||
| 305 | * are identified by appending a colon. |
||
| 306 | * |
||
| 307 | * @return bool |
||
| 308 | * @author Adrian Lang <[email protected]> |
||
| 309 | */ |
||
| 310 | protected function unlock($id) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Send a digest mail |
||
| 319 | * |
||
| 320 | * Sends a digest mail showing a bunch of changes of a single page. Basically the same as send_diff() |
||
| 321 | * but determines the last known revision first |
||
| 322 | * |
||
| 323 | * @param string $subscriber_mail The target mail address |
||
| 324 | * @param string $id The ID |
||
| 325 | * @param int $lastupdate Time of the last notification |
||
| 326 | * |
||
| 327 | * @return bool |
||
| 328 | * @author Adrian Lang <[email protected]> |
||
| 329 | * |
||
| 330 | */ |
||
| 331 | protected function sendDigest($subscriber_mail, $id, $lastupdate) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Send a list mail |
||
| 350 | * |
||
| 351 | * Sends a list mail showing a list of changed pages. |
||
| 352 | * |
||
| 353 | * @param string $subscriber_mail The target mail address |
||
| 354 | * @param array $ids Array of ids |
||
| 355 | * @param string $ns_id The id of the namespace |
||
| 356 | * |
||
| 357 | * @return bool true if a mail was sent |
||
| 358 | * @author Adrian Lang <[email protected]> |
||
| 359 | * |
||
| 360 | */ |
||
| 361 | protected function sendList($subscriber_mail, $ids, $ns_id) |
||
| 395 | } |
||
| 396 |