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() { |
||
98 | |||
99 | /** |
||
100 | * Returns the description of an configured blog or false if it is not configured |
||
101 | * |
||
102 | * @param int $blog_id |
||
103 | * @param string|bool $description |
||
104 | * |
||
105 | * @return string|bool |
||
106 | */ |
||
107 | public static function get_configured_blog_description( $blog_id, $description = false ) { |
||
119 | |||
120 | /** |
||
121 | * Gets the list of the blogs of the reference user |
||
122 | * The first available user of the blog will be used if there is no |
||
123 | * refrence user configured |
||
124 | * |
||
125 | * @param MslsOptions $options |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | public function get_blogs_of_reference_user( MslsOptions $options ) { |
||
147 | |||
148 | /** |
||
149 | * Get blog by language |
||
150 | * |
||
151 | * @param string $language |
||
152 | * |
||
153 | * @return MslsBlog|null |
||
154 | */ |
||
155 | public function get_blog( $language ) { |
||
167 | |||
168 | /** |
||
169 | * Gets blog_id by language |
||
170 | * |
||
171 | * @param string $language |
||
172 | * |
||
173 | * @return string|null |
||
174 | */ |
||
175 | public function get_blog_id( $language ) { |
||
181 | |||
182 | /** |
||
183 | * Get the id of the current blog |
||
184 | * @return int |
||
185 | */ |
||
186 | public function get_current_blog_id() { |
||
189 | |||
190 | /** |
||
191 | * Checks if blog is the current blog |
||
192 | * |
||
193 | * @param MslsBlog $blog |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function is_current_blog( MslsBlog $blog ) { |
||
200 | |||
201 | /** |
||
202 | * Checks if current blog is in the collection |
||
203 | * |
||
204 | * @return bool |
||
205 | */ |
||
206 | public function has_current_blog() { |
||
209 | |||
210 | /** |
||
211 | * Gets current blog as object |
||
212 | * @return MslsBlog|null |
||
213 | */ |
||
214 | public function get_current_blog() { |
||
217 | |||
218 | /** |
||
219 | * Gets an array with all blog-objects |
||
220 | * @return MslsBlog[] |
||
221 | */ |
||
222 | public function get_objects() { |
||
225 | |||
226 | /** |
||
227 | * Is plugin active in the blog with that blog_id |
||
228 | * |
||
229 | * @param int $blog_id |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | public function is_plugin_active( $blog_id ) { |
||
246 | |||
247 | /** |
||
248 | * Gets only blogs where the plugin is active |
||
249 | * @return array |
||
250 | */ |
||
251 | public function get_plugin_active_blogs() { |
||
262 | |||
263 | /** |
||
264 | * Gets an array of all - but not the current - blog-objects |
||
265 | * @return MslsBlog[] |
||
266 | */ |
||
267 | public function get() { |
||
276 | |||
277 | /** |
||
278 | * Gets an array with filtered blog-objects |
||
279 | * |
||
280 | * @param bool $filter |
||
281 | * |
||
282 | * @return MslsBlog[] |
||
283 | */ |
||
284 | public function get_filtered( $filter = false ) { |
||
291 | |||
292 | /** |
||
293 | * Gets the registered users of the current blog |
||
294 | * |
||
295 | * @param string $fields |
||
296 | * @param int|string $number |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | public function get_users( $fields = 'all', $number = '' ) { |
||
313 | |||
314 | /** |
||
315 | * Returns a specific blog language. |
||
316 | * |
||
317 | * @param int $blog_id |
||
318 | * @param string $default |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | public static function get_blog_language( $blog_id = null, $default = 'en_US' ) { |
||
331 | |||
332 | } |
||
333 |