Complex classes like MslsBlogCollection 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 MslsBlogCollection, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class MslsBlogCollection extends MslsRegistryInstance { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * ID of the current blog |
||
| 19 | * @var int |
||
| 20 | */ |
||
| 21 | private $current_blog_id; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * True if the current blog should be in the output |
||
| 25 | * @var bool |
||
| 26 | */ |
||
| 27 | private $current_blog_output; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Collection of MslsBlog-objects |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | private $objects = array(); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Order output by language or description |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | private $objects_order; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Active plugins in the whole network |
||
| 43 | * @var array |
||
| 44 | */ |
||
| 45 | private $active_plugins; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Constructor |
||
| 49 | */ |
||
| 50 | public function __construct() { |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Returns the description of an configured blog or false if it is not configured |
||
| 102 | * |
||
| 103 | * @param int $blog_id |
||
| 104 | * @param string|bool $description |
||
| 105 | * |
||
| 106 | * @return string|bool |
||
| 107 | */ |
||
| 108 | public static function get_configured_blog_description( $blog_id, $description = false ) { |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Gets the list of the blogs of the reference user |
||
| 123 | * The first available user of the blog will be used if there is no |
||
| 124 | * refrence user configured |
||
| 125 | * |
||
| 126 | * @param MslsOptions $options |
||
| 127 | * |
||
| 128 | * @return array |
||
| 129 | */ |
||
| 130 | public function get_blogs_of_reference_user( MslsOptions $options ) { |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Gets blog(s) by language |
||
| 151 | */ |
||
| 152 | public function get_blog_id( $language ) { |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Get the id of the current blog |
||
| 167 | * @return int |
||
| 168 | */ |
||
| 169 | public function get_current_blog_id() { |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Checks if current blog is in the collection |
||
| 175 | * |
||
| 176 | * @return bool |
||
| 177 | */ |
||
| 178 | public function has_current_blog() { |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Gets current blog as object |
||
| 184 | * @return MslsBlog|null |
||
| 185 | */ |
||
| 186 | public function get_current_blog() { |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Gets an array with all blog-objects |
||
| 196 | * @return MslsBlog[] |
||
| 197 | */ |
||
| 198 | public function get_objects() { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Is plugin active in the blog with that blog_id |
||
| 204 | * |
||
| 205 | * @param int $blog_id |
||
| 206 | * |
||
| 207 | * @return bool |
||
| 208 | */ |
||
| 209 | public function is_plugin_active( $blog_id ) { |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Gets only blogs where the plugin is active |
||
| 228 | * @return array |
||
| 229 | */ |
||
| 230 | public function get_plugin_active_blogs() { |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Gets an array of all - but not the current - blog-objects |
||
| 244 | * @return array |
||
| 245 | */ |
||
| 246 | public function get() { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Gets an array with filtered blog-objects |
||
| 257 | * |
||
| 258 | * @param bool $filter |
||
| 259 | * |
||
| 260 | * @return array |
||
| 261 | */ |
||
| 262 | public function get_filtered( $filter = false ) { |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Gets the registered users of the current blog |
||
| 272 | * |
||
| 273 | * @param string $fields |
||
| 274 | * @param int|string $number |
||
| 275 | * |
||
| 276 | * @return array |
||
| 277 | */ |
||
| 278 | public function get_users( $fields = 'all', $number = '' ) { |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Returns a specific blog language. |
||
| 291 | * |
||
| 292 | * @param int $blog_id |
||
| 293 | * |
||
| 294 | * @return string |
||
| 295 | */ |
||
| 296 | public static function get_blog_language( $blog_id = null ) { |
||
| 307 | |||
| 308 | } |
||
| 309 |