Complex classes like SWLGroup 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 SWLGroup, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class SWLGroup { |
||
15 | |||
16 | /** |
||
17 | * The ID of the group; the group_id field in swl_groups. |
||
18 | * When creating a new group, this will be null, and |
||
19 | * automatically set after writing the group to the DB. |
||
20 | * |
||
21 | * @since 0.1 |
||
22 | * |
||
23 | * @var integer or null |
||
24 | */ |
||
25 | private $id; |
||
26 | |||
27 | /** |
||
28 | * Name of the group. |
||
29 | * |
||
30 | * @since 0.1 |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $name; |
||
35 | |||
36 | /** |
||
37 | * List of categories this group covers. |
||
38 | * |
||
39 | * @since 0.1 |
||
40 | * |
||
41 | * @var array of string |
||
42 | */ |
||
43 | private $categories; |
||
44 | |||
45 | /** |
||
46 | * List of namespaces IDs of namespaces this group covers. |
||
47 | * |
||
48 | * @since 0.1 |
||
49 | * |
||
50 | * @var array of integer |
||
51 | */ |
||
52 | private $namespaces = array(); |
||
53 | |||
54 | /** |
||
55 | * List of SMW properties this group covers. |
||
56 | * |
||
57 | * @since 0.1 |
||
58 | * |
||
59 | * @var array of string |
||
60 | */ |
||
61 | private $properties; |
||
62 | |||
63 | /** |
||
64 | * List of custom texts this group covers. |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | private $customTexts; |
||
69 | |||
70 | /** |
||
71 | * List of SMW concepts this group covers. |
||
72 | * |
||
73 | * @since 0.1 |
||
74 | * |
||
75 | * @var array of string |
||
76 | */ |
||
77 | private $concepts; |
||
78 | |||
79 | /** |
||
80 | * Cached list of IDs of users that are watching this group, |
||
81 | * or false if this data has not been obtained yet. |
||
82 | * |
||
83 | * @since 0.1 |
||
84 | * |
||
85 | * @var array of integer or false |
||
86 | */ |
||
87 | private $watchingUsers = false; |
||
88 | |||
89 | /** |
||
90 | * Creates a new instance of SWLGroup from a DB result. |
||
91 | * |
||
92 | * @since 0.1 |
||
93 | * |
||
94 | * @param $group |
||
95 | * |
||
96 | * @return SWLGroup |
||
97 | */ |
||
98 | public static function newFromDBResult( $group ) { |
||
109 | |||
110 | /** |
||
111 | * Constructor. |
||
112 | * |
||
113 | * @since 0.1 |
||
114 | * |
||
115 | * @param integer $id Set to null when creating a new group. |
||
116 | * @param string $name |
||
117 | * @param array $categories List of category names |
||
118 | * @param array $namespaces List of namespace names or IDs |
||
119 | * @param array $properties List of property names |
||
120 | * @param array $concepts List of concept names |
||
121 | * @param array $customTexts List of custom texts |
||
122 | */ |
||
123 | public function __construct( $id, $name, array $categories, array $namespaces, array $properties, array $concepts, array $customTexts ) { |
||
147 | |||
148 | /** |
||
149 | * Writes the group to the database, either updating it |
||
150 | * when it already exists, or inserting it when it doesn't. |
||
151 | * |
||
152 | * @since 0.1 |
||
153 | * |
||
154 | * @return boolean Success indicator |
||
155 | */ |
||
156 | public function writeToDB() { |
||
164 | |||
165 | /** |
||
166 | * Updates the group in the database. |
||
167 | * |
||
168 | * @since 0.1 |
||
169 | * |
||
170 | * @return boolean Success indicator |
||
171 | */ |
||
172 | private function updateInDB() { |
||
187 | |||
188 | /** |
||
189 | * Inserts the group into the database. |
||
190 | * |
||
191 | * @since 0.1 |
||
192 | * |
||
193 | * @return boolean Success indicator |
||
194 | */ |
||
195 | private function insertIntoDB() { |
||
214 | |||
215 | /** |
||
216 | * Returns the categories specified by the group. |
||
217 | * |
||
218 | * @since 0.1 |
||
219 | * |
||
220 | * @return array[string] |
||
|
|||
221 | */ |
||
222 | public function getCategories() { |
||
225 | |||
226 | /** |
||
227 | * Returns the namespaces specified by the group. |
||
228 | * |
||
229 | * @since 0.1 |
||
230 | * |
||
231 | * @return array[integer] |
||
232 | */ |
||
233 | public function getNamespaces() { |
||
236 | |||
237 | /** |
||
238 | * Returns the properties specified by the group as strings (serializations of SMWDIProperty). |
||
239 | * |
||
240 | * @since 0.1 |
||
241 | * |
||
242 | * @return array[string] |
||
243 | */ |
||
244 | public function getProperties() { |
||
247 | |||
248 | /** |
||
249 | * Returns the properties specified by the group as SMWDIProperty objects. |
||
250 | * |
||
251 | * @since 0.1 |
||
252 | * |
||
253 | * @return array[SMWDIProperty] |
||
254 | */ |
||
255 | public function getPropertyObjects() { |
||
264 | |||
265 | /** |
||
266 | * Returns the concepts specified by the group. |
||
267 | * |
||
268 | * @since 0.1 |
||
269 | * |
||
270 | * @return array[string] |
||
271 | */ |
||
272 | public function getConcepts() { |
||
275 | |||
276 | /** |
||
277 | * Returns the custom Texts specified for this group. |
||
278 | * |
||
279 | * @since 0.2 |
||
280 | * |
||
281 | * @return array |
||
282 | */ |
||
283 | public function getCustomTexts() { |
||
286 | |||
287 | /** |
||
288 | * Returns the serialized version of custom Texts specified for this group. |
||
289 | * |
||
290 | * @since 0.2 |
||
291 | * |
||
292 | * @return array |
||
293 | */ |
||
294 | public function getSerializedCustomTexts() { |
||
301 | |||
302 | /** |
||
303 | * Returns the unserialized version of custom Texts specified for this group. |
||
304 | * |
||
305 | * @return array |
||
306 | */ |
||
307 | public static function unserializedCustomTexts( $customTexts ) { |
||
314 | |||
315 | /** |
||
316 | * Returns the group database id. |
||
317 | * |
||
318 | * @since 0.1 |
||
319 | * |
||
320 | * @return integer |
||
321 | */ |
||
322 | public function getId() { |
||
325 | |||
326 | /** |
||
327 | * Returns the group name. |
||
328 | * |
||
329 | * @since 0.1 |
||
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | public function getName() { |
||
336 | |||
337 | /** |
||
338 | * Returns whether the group contains the specified page. |
||
339 | * |
||
340 | * @since 0.1 |
||
341 | * |
||
342 | * @param Title $title |
||
343 | * |
||
344 | * @return boolean |
||
345 | */ |
||
346 | public function coversPage( Title $title ) { |
||
351 | |||
352 | /** |
||
353 | * Returns whether the namespaces of the group cover the specified page. |
||
354 | * |
||
355 | * @since 0.1 |
||
356 | * |
||
357 | * @param Title $title |
||
358 | * |
||
359 | * @return boolean |
||
360 | */ |
||
361 | public function namespacesCoversPage( Title $title ) { |
||
370 | |||
371 | /** |
||
372 | * Returns whether the catgeories of the group cover the specified page. |
||
373 | * |
||
374 | * @since 0.1 |
||
375 | * |
||
376 | * @param Title $title |
||
377 | * |
||
378 | * @return boolean |
||
379 | */ |
||
380 | public function categoriesCoverPage( Title $title ) { |
||
406 | |||
407 | /** |
||
408 | * Returns whether the concepts of the group cover the specified page. |
||
409 | * |
||
410 | * @since 0.1 |
||
411 | * |
||
412 | * @param Title $title |
||
413 | * |
||
414 | * @return boolean |
||
415 | */ |
||
416 | public function conceptsCoverPage( Title $title ) { |
||
445 | |||
446 | /** |
||
447 | * Returns the IDs of the users watching the group. |
||
448 | * |
||
449 | * @since 0.1 |
||
450 | * |
||
451 | * @return array of integer |
||
452 | */ |
||
453 | public function getWatchingUsers() { |
||
478 | |||
479 | /** |
||
480 | * Returns if the group is watched by the specified user or not. |
||
481 | * |
||
482 | * @since 0.1 |
||
483 | * |
||
484 | * @param User $user |
||
485 | * |
||
486 | * @return boolean |
||
487 | */ |
||
488 | public function isWatchedByUser( User $user ) { |
||
491 | |||
492 | /** |
||
493 | * Gets all the watching users and passes them, together with the specified |
||
494 | * changes and the group object itself, to the SWLGroupNotify hook. |
||
495 | * |
||
496 | * @since 0.1 |
||
497 | * |
||
498 | * @param SMWChangeSet $changes |
||
499 | */ |
||
500 | public function notifyWatchingUsers( SWLChangeSet $changes ) { |
||
507 | |||
508 | } |
||
509 | |||
510 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.