Complex classes like DocumentProperties 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 DocumentProperties, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class DocumentProperties |
||
28 | { |
||
29 | /** constants */ |
||
30 | const PROPERTY_TYPE_BOOLEAN = 'b'; |
||
31 | const PROPERTY_TYPE_INTEGER = 'i'; |
||
32 | const PROPERTY_TYPE_FLOAT = 'f'; |
||
33 | const PROPERTY_TYPE_DATE = 'd'; |
||
34 | const PROPERTY_TYPE_STRING = 's'; |
||
35 | const PROPERTY_TYPE_UNKNOWN = 'u'; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Creator |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $creator = ''; |
||
44 | |||
45 | /** |
||
46 | * LastModifiedBy |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | private $lastModifiedBy; |
||
51 | |||
52 | /** |
||
53 | * Created |
||
54 | * |
||
55 | * @var int |
||
56 | */ |
||
57 | private $created; |
||
58 | |||
59 | /** |
||
60 | * Modified |
||
61 | * |
||
62 | * @var int |
||
63 | */ |
||
64 | private $modified; |
||
65 | |||
66 | /** |
||
67 | * Title |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | private $title = ''; |
||
72 | |||
73 | /** |
||
74 | * Description |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | private $description = ''; |
||
79 | |||
80 | /** |
||
81 | * Subject |
||
82 | * |
||
83 | * @var string |
||
84 | */ |
||
85 | private $subject = ''; |
||
86 | |||
87 | /** |
||
88 | * Keywords |
||
89 | * |
||
90 | * @var string |
||
91 | */ |
||
92 | private $keywords = ''; |
||
93 | |||
94 | /** |
||
95 | * Category |
||
96 | * |
||
97 | * @var string |
||
98 | */ |
||
99 | private $category = ''; |
||
100 | |||
101 | /** |
||
102 | * Manager |
||
103 | * |
||
104 | * @var string |
||
105 | */ |
||
106 | private $manager = ''; |
||
107 | |||
108 | /** |
||
109 | * Company |
||
110 | * |
||
111 | * @var string |
||
112 | */ |
||
113 | private $company = ''; |
||
114 | |||
115 | /** |
||
116 | * Custom Properties |
||
117 | * |
||
118 | * @var string[] |
||
119 | */ |
||
120 | private $customProperties = array(); |
||
121 | |||
122 | |||
123 | /** |
||
124 | * Create a new PHPProject_DocumentProperties |
||
125 | */ |
||
126 | 37 | public function __construct() |
|
131 | |||
132 | /** |
||
133 | * Get Creator |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 1 | public function getCreator() |
|
141 | |||
142 | /** |
||
143 | * Set Creator |
||
144 | * |
||
145 | * @param string $pValue |
||
146 | * @return PHPProject_DocumentProperties |
||
147 | */ |
||
148 | 1 | public function setCreator($pValue = '') |
|
153 | |||
154 | /** |
||
155 | * Get Last Modified By |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 1 | public function getLastModifiedBy() |
|
163 | |||
164 | /** |
||
165 | * Set Last Modified By |
||
166 | * |
||
167 | * @param string $pValue |
||
168 | * @return PHPProject_DocumentProperties |
||
169 | */ |
||
170 | 1 | public function setLastModifiedBy($pValue = '') |
|
175 | |||
176 | /** |
||
177 | * Get Created |
||
178 | * |
||
179 | * @return int |
||
180 | */ |
||
181 | 1 | public function getCreated() |
|
185 | |||
186 | /** |
||
187 | * Set Created |
||
188 | * |
||
189 | * @param int $pValue |
||
190 | * @return PHPProject_DocumentProperties |
||
191 | */ |
||
192 | 1 | public function setCreated($pValue = null) |
|
207 | |||
208 | /** |
||
209 | * Get Modified |
||
210 | * |
||
211 | * @return int |
||
212 | */ |
||
213 | 1 | public function getModified() |
|
217 | |||
218 | /** |
||
219 | * Set Modified |
||
220 | * |
||
221 | * @param int $pValue |
||
222 | * @return PHPProject_DocumentProperties |
||
223 | */ |
||
224 | 1 | public function setModified($pValue = null) |
|
239 | |||
240 | /** |
||
241 | * Get Title |
||
242 | * |
||
243 | * @return string |
||
244 | */ |
||
245 | 1 | public function getTitle() |
|
249 | |||
250 | /** |
||
251 | * Set Title |
||
252 | * |
||
253 | * @param string $pValue |
||
254 | * @return PHPProject_DocumentProperties |
||
255 | */ |
||
256 | 1 | public function setTitle($pValue = '') |
|
261 | |||
262 | /** |
||
263 | * Get Description |
||
264 | * |
||
265 | * @return string |
||
266 | */ |
||
267 | 1 | public function getDescription() |
|
271 | |||
272 | /** |
||
273 | * Set Description |
||
274 | * |
||
275 | * @param string $pValue |
||
276 | * @return PHPProject_DocumentProperties |
||
277 | */ |
||
278 | 2 | public function setDescription($pValue = '') |
|
283 | |||
284 | /** |
||
285 | * Get Subject |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | 1 | public function getSubject() |
|
293 | |||
294 | /** |
||
295 | * Set Subject |
||
296 | * |
||
297 | * @param string $pValue |
||
298 | * @return PHPProject_DocumentProperties |
||
299 | */ |
||
300 | 1 | public function setSubject($pValue = '') |
|
305 | |||
306 | /** |
||
307 | * Get Keywords |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | 1 | public function getKeywords() |
|
315 | |||
316 | /** |
||
317 | * Set Keywords |
||
318 | * |
||
319 | * @param string $pValue |
||
320 | * @return PHPProject_DocumentProperties |
||
321 | */ |
||
322 | 1 | public function setKeywords($pValue = '') |
|
327 | |||
328 | /** |
||
329 | * Get Category |
||
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | 1 | public function getCategory() |
|
337 | |||
338 | /** |
||
339 | * Set Category |
||
340 | * |
||
341 | * @param string $pValue |
||
342 | * @return PHPProject_DocumentProperties |
||
343 | */ |
||
344 | 1 | public function setCategory($pValue = '') |
|
349 | |||
350 | /** |
||
351 | * Get Company |
||
352 | * |
||
353 | * @return string |
||
354 | */ |
||
355 | 1 | public function getCompany() |
|
359 | |||
360 | /** |
||
361 | * Set Company |
||
362 | * |
||
363 | * @param string $pValue |
||
364 | * @return PHPProject_DocumentProperties |
||
365 | */ |
||
366 | 1 | public function setCompany($pValue = '') |
|
371 | |||
372 | /** |
||
373 | * Get Manager |
||
374 | * |
||
375 | * @return string |
||
376 | */ |
||
377 | 1 | public function getManager() |
|
381 | |||
382 | /** |
||
383 | * Set Manager |
||
384 | * |
||
385 | * @param string $pValue |
||
386 | * @return PHPProject_DocumentProperties |
||
387 | */ |
||
388 | 1 | public function setManager($pValue = '') |
|
393 | |||
394 | /** |
||
395 | * Get a List of Custom Property Names |
||
396 | * |
||
397 | * @return string[] |
||
398 | */ |
||
399 | 1 | public function getCustomProperties() |
|
403 | |||
404 | /** |
||
405 | * Check if a Custom Property is defined |
||
406 | * |
||
407 | * @param string $propertyName |
||
408 | * @return boolean |
||
409 | */ |
||
410 | 1 | public function isCustomPropertySet($propertyName) |
|
414 | |||
415 | /** |
||
416 | * Get a Custom Property Value |
||
417 | * |
||
418 | * @param string $propertyName |
||
419 | * @return string |
||
420 | */ |
||
421 | 1 | public function getCustomPropertyValue($propertyName) |
|
428 | |||
429 | /** |
||
430 | * Get a Custom Property Type |
||
431 | * |
||
432 | * @param string $propertyName |
||
433 | * @return string |
||
434 | */ |
||
435 | 1 | public function getCustomPropertyType($propertyName) |
|
442 | |||
443 | /** |
||
444 | * Set a Custom Property |
||
445 | * |
||
446 | * @param string $propertyName |
||
447 | * @param mixed $propertyValue |
||
448 | * @param string $propertyType |
||
449 | * 'i': Integer |
||
450 | * 'f': Floating Point |
||
451 | * 's': String |
||
452 | * 'd': Date/Time |
||
453 | * 'b': Boolean |
||
454 | * @return PHPProject_DocumentProperties |
||
455 | */ |
||
456 | 1 | public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null) |
|
473 | |||
474 | 1 | public static function convertProperty($propertyValue, $propertyType) |
|
530 | |||
531 | 1 | public static function convertPropertyType($propertyType) |
|
585 | } |
||
586 |