Complex classes like m_quota 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 m_quota, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
39 | class m_quota { |
||
40 | |||
41 | var $disk = Array(); /* disk resource for which we will manage quotas */ |
||
42 | var $disk_quota_enable; |
||
43 | var $quotas; |
||
44 | var $clquota; // Which class manage which quota. |
||
45 | |||
46 | /* ----------------------------------------------------------------- */ |
||
47 | |||
48 | /** |
||
49 | * Constructor |
||
50 | */ |
||
51 | function m_quota() { |
||
57 | |||
58 | private function dummy_for_translation() { |
||
61 | |||
62 | function hook_menu() { |
||
89 | |||
90 | function hook_homepageblock() { |
||
99 | |||
100 | /* ----------------------------------------------------------------- */ |
||
101 | |||
102 | /** Check if a user can use a ressource. |
||
103 | * @param string $ressource the ressource name (a named quota) |
||
104 | * @Return TRUE if the user can create a ressource (= is there any quota left ?) |
||
105 | * @return boolean |
||
106 | */ |
||
107 | function cancreate($ressource = "") { |
||
111 | |||
112 | /* ----------------------------------------------------------------- */ |
||
113 | |||
114 | /** List the quota-managed services in the server |
||
115 | * @Return array the quota names and description (translated) |
||
116 | */ |
||
117 | function qlist() { |
||
131 | |||
132 | /** |
||
133 | * Synchronise the quotas of the users with the quota of the |
||
134 | * user's profile. |
||
135 | * If the user have a greater quota than the profile, no change. |
||
136 | * If the quota entry doesn't exist for the user, create it with |
||
137 | * the defaults value. |
||
138 | */ |
||
139 | function synchronise_user_profile() { |
||
148 | |||
149 | /* |
||
150 | * Create default quota in the profile |
||
151 | * when a new quota appear |
||
152 | * |
||
153 | */ |
||
154 | |||
155 | function create_missing_quota_profile() { |
||
167 | |||
168 | /* ----------------------------------------------------------------- */ |
||
169 | |||
170 | /** Return a ressource usage (u) and total quota (t) |
||
171 | * @param string $ressource ressource to get quota of |
||
172 | * @Return array the quota used and total for this ressource (or for all ressource if unspecified) |
||
173 | */ |
||
174 | function getquota($ressource = "", $recheck = false) { |
||
235 | |||
236 | /* ----------------------------------------------------------------- */ |
||
237 | |||
238 | /** Set the quota for a user (and for a ressource) |
||
239 | * @param string $ressource ressource to set quota of |
||
240 | * @param integer size of the quota (available or used) |
||
241 | */ |
||
242 | function setquota($ressource, $size) { |
||
268 | |||
269 | /* ----------------------------------------------------------------- */ |
||
270 | |||
271 | /** |
||
272 | * Erase all quota information about the user. |
||
273 | */ |
||
274 | function delquotas() { |
||
280 | |||
281 | /* ----------------------------------------------------------------- */ |
||
282 | |||
283 | /** Get the default quotas as an associative array |
||
284 | * @return array the array of the default quotas |
||
285 | */ |
||
286 | function getdefaults() { |
||
301 | |||
302 | /* ----------------------------------------------------------------- */ |
||
303 | |||
304 | /** Set the default quotas |
||
305 | * @param array associative array of quota (key=>val) |
||
306 | */ |
||
307 | function setdefaults($newq) { |
||
322 | |||
323 | /* ----------------------------------------------------------------- */ |
||
324 | |||
325 | /** Add an account type for quotas |
||
326 | * @param string $type account type to be added |
||
327 | * @return boolean true if all went ok |
||
328 | */ |
||
329 | function addtype($type) { |
||
347 | |||
348 | /* ----------------------------------------------------------------- */ |
||
349 | |||
350 | /** List for quotas |
||
351 | * @return array |
||
352 | */ |
||
353 | function listtype() { |
||
362 | |||
363 | /* ----------------------------------------------------------------- */ |
||
364 | |||
365 | /** Delete an account type for quotas |
||
366 | * @param string $type account type to be deleted |
||
367 | * @return boolean true if all went ok |
||
368 | */ |
||
369 | function deltype($type) { |
||
379 | |||
380 | /* ----------------------------------------------------------------- */ |
||
381 | |||
382 | /** Create default quotas entries for a new user. |
||
383 | * The user we are talking about is in the global $cuid. |
||
384 | */ |
||
385 | function addquotas() { |
||
406 | |||
407 | /* ----------------------------------------------------------------- */ |
||
408 | |||
409 | /** Return a quota value with its unit (when it is a space quota) |
||
410 | * in MB, GB, TB ... |
||
411 | * @param string $type The quota type |
||
412 | * @param integer $value The quota value |
||
413 | * @return string a quota value with its unit. |
||
414 | */ |
||
415 | function display_val($type, $value) { |
||
425 | |||
426 | /* get size_xx function (filled by spoolsize.php) */ |
||
427 | |||
428 | function _get_sum_sql($sql) { |
||
439 | |||
440 | function _get_count_sql($sql) { |
||
451 | |||
452 | function _get_size_and_record_sql($sql) { |
||
465 | |||
466 | /* sum of websites sizes from all users */ |
||
467 | |||
468 | function get_size_web_sum_all() { |
||
471 | |||
472 | /* sum of websites sizes from one user */ |
||
473 | |||
474 | function get_size_web_sum_user($u) { |
||
477 | |||
478 | /* sum of mailbox sizes from all domains */ |
||
479 | |||
480 | function get_size_mail_sum_all() { |
||
483 | |||
484 | /* sum of mailbox sizes for one domain */ |
||
485 | |||
486 | function get_size_mail_sum_domain($dom) { |
||
490 | |||
491 | /* count of mailbox sizes from all domains */ |
||
492 | |||
493 | function get_size_mail_count_all() { |
||
496 | |||
497 | /* count of mailbox for one domain */ |
||
498 | |||
499 | function get_size_mail_count_domain($dom) { |
||
502 | |||
503 | /* get list of mailbox alias and size for one domain */ |
||
504 | |||
505 | function get_size_mail_details_domain($dom) { |
||
508 | |||
509 | /* sum of mailman lists sizes from all domains */ |
||
510 | |||
511 | function get_size_mailman_sum_all() { |
||
514 | |||
515 | /* sum of mailman lists sizes for one domain */ |
||
516 | |||
517 | function get_size_mailman_sum_domain($dom) { |
||
520 | |||
521 | /* sum of mailman lists for one user */ |
||
522 | |||
523 | function get_size_mailman_sum_user($u) { |
||
526 | |||
527 | /* count of mailman lists sizes from all domains */ |
||
528 | |||
529 | function get_size_mailman_count_all() { |
||
532 | |||
533 | /* count of mailman lists for one user */ |
||
534 | |||
535 | function get_size_mailman_count_user($u) { |
||
538 | |||
539 | /* get list of mailman list and size for one user */ |
||
540 | |||
541 | function get_size_mailman_details_user($u) { |
||
544 | |||
545 | /* sum of databases sizes from all users */ |
||
546 | |||
547 | function get_size_db_sum_all() { |
||
550 | |||
551 | /* sum of databases sizes for one user */ |
||
552 | |||
553 | function get_size_db_sum_user($u) { |
||
556 | |||
557 | /* count of databases from all users */ |
||
558 | |||
559 | function get_size_db_count_all() { |
||
562 | |||
563 | /* count of databases for one user */ |
||
564 | |||
565 | function get_size_db_count_user($u) { |
||
568 | |||
569 | /* get list of databases name and size for one user */ |
||
570 | |||
571 | function get_size_db_details_user($u) { |
||
574 | |||
575 | /* Return appropriate value and unit of a size given in Bytes (e.g. 1024 Bytes -> return 1 KB) */ |
||
576 | |||
577 | function get_size_unit($size) { |
||
586 | |||
587 | // Affiche des barres de progression |
||
588 | // color_type : |
||
589 | // 0 = Pas de changement de couleur |
||
590 | // 1 = Progression du vert vers le rouge en fonction du porcentage |
||
591 | // 2 = Progression du rouge vers le vert en fonction du porcentage |
||
592 | function quota_displaybar($usage, $color_type = 1) { |
||
607 | |||
608 | /* ==== Hook functions ==== */ |
||
609 | |||
610 | /* ----------------------------------------------------------------- */ |
||
611 | |||
612 | /** Hook function call when a user is deleted |
||
613 | * AlternC's standard function called when a user is deleted |
||
614 | * globals $cuid is the appropriate user |
||
615 | */ |
||
616 | function hook_admin_del_member() { |
||
619 | |||
620 | /* ----------------------------------------------------------------- */ |
||
621 | |||
622 | /** Hook function called when a user is created |
||
623 | * This function initialize the user's quotas. |
||
624 | * globals $cuid is the appropriate user |
||
625 | */ |
||
626 | function hook_admin_add_member() { |
||
632 | |||
633 | /* ----------------------------------------------------------------- */ |
||
634 | |||
635 | /** Exports all the quota related information for an account. |
||
636 | * @access private |
||
637 | * EXPERIMENTAL function ;) |
||
638 | */ |
||
639 | function alternc_export_conf() { |
||
654 | |||
655 | } |
||
656 | |||
659 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.