Complex classes like BaseFieldDescription 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 BaseFieldDescription, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
60 | abstract class BaseFieldDescription implements FieldDescriptionInterface |
||
61 | { |
||
62 | /** |
||
63 | * @var string the field name |
||
64 | */ |
||
65 | protected $name; |
||
66 | |||
67 | /** |
||
68 | * @var string|int the type |
||
69 | */ |
||
70 | protected $type; |
||
71 | |||
72 | /** |
||
73 | * @var string|int the original mapping type |
||
74 | */ |
||
75 | protected $mappingType; |
||
76 | |||
77 | /** |
||
78 | * @var string the field name (of the form) |
||
79 | */ |
||
80 | protected $fieldName; |
||
81 | |||
82 | /** |
||
83 | * @var array the ORM association mapping |
||
84 | */ |
||
85 | protected $associationMapping; |
||
86 | |||
87 | /** |
||
88 | * @var array the ORM field information |
||
89 | */ |
||
90 | protected $fieldMapping; |
||
91 | |||
92 | /** |
||
93 | * @var array the ORM parent mapping association |
||
94 | */ |
||
95 | protected $parentAssociationMappings; |
||
96 | |||
97 | /** |
||
98 | * @var string the template name |
||
99 | */ |
||
100 | protected $template; |
||
101 | |||
102 | /** |
||
103 | * @var array the option collection |
||
104 | */ |
||
105 | protected $options = []; |
||
106 | |||
107 | /** |
||
108 | * @var AdminInterface|null the parent Admin instance |
||
109 | */ |
||
110 | protected $parent = null; |
||
111 | |||
112 | /** |
||
113 | * @var AdminInterface the related admin instance |
||
114 | */ |
||
115 | protected $admin; |
||
116 | |||
117 | /** |
||
118 | * @var AdminInterface the associated admin class if the object is associated to another entity |
||
119 | */ |
||
120 | protected $associationAdmin; |
||
121 | |||
122 | /** |
||
123 | * @var string the help message to display |
||
124 | */ |
||
125 | protected $help; |
||
126 | |||
127 | public function setFieldName($fieldName) |
||
131 | |||
132 | public function getFieldName() |
||
136 | |||
137 | public function setName($name) |
||
145 | |||
146 | public function getName() |
||
150 | |||
151 | public function getOption($name, $default = null) |
||
155 | |||
156 | public function setOption($name, $value) |
||
160 | |||
161 | public function setOptions(array $options) |
||
192 | |||
193 | public function getOptions() |
||
197 | |||
198 | public function setTemplate($template) |
||
202 | |||
203 | public function getTemplate() |
||
207 | |||
208 | public function setType($type) |
||
212 | |||
213 | public function getType() |
||
217 | |||
218 | public function setParent(AdminInterface $parent) |
||
222 | |||
223 | public function getParent() |
||
227 | |||
228 | public function getAssociationMapping() |
||
232 | |||
233 | public function getFieldMapping() |
||
237 | |||
238 | public function getParentAssociationMappings() |
||
242 | |||
243 | public function setAssociationAdmin(AdminInterface $associationAdmin) |
||
248 | |||
249 | public function getAssociationAdmin() |
||
253 | |||
254 | public function hasAssociationAdmin() |
||
258 | |||
259 | public function getFieldValue($object, $fieldName) |
||
301 | |||
302 | public function setAdmin(AdminInterface $admin) |
||
306 | |||
307 | public function getAdmin() |
||
311 | |||
312 | public function mergeOption($name, array $options = []) |
||
324 | |||
325 | public function mergeOptions(array $options = []) |
||
329 | |||
330 | public function setMappingType($mappingType) |
||
334 | |||
335 | public function getMappingType() |
||
339 | |||
340 | /** |
||
341 | * Camelize a string. |
||
342 | * |
||
343 | * NEXT_MAJOR: remove this method. |
||
344 | * |
||
345 | * @static |
||
346 | * |
||
347 | * @param string $property |
||
348 | * |
||
349 | * @return string |
||
350 | * |
||
351 | * @deprecated Deprecated since version 3.1. Use \Doctrine\Common\Inflector\Inflector::classify() instead |
||
352 | */ |
||
353 | public static function camelize($property) |
||
366 | |||
367 | /** |
||
368 | * Defines the help message. |
||
369 | * |
||
370 | * @param string $help |
||
371 | */ |
||
372 | public function setHelp($help) |
||
376 | |||
377 | public function getHelp() |
||
381 | |||
382 | public function getLabel() |
||
386 | |||
387 | public function isSortable() |
||
391 | |||
392 | public function getSortFieldMapping() |
||
396 | |||
397 | public function getSortParentAssociationMapping() |
||
401 | |||
402 | public function getTranslationDomain() |
||
406 | |||
407 | /** |
||
408 | * Return true if field is virtual. |
||
409 | * |
||
410 | * @return bool |
||
411 | */ |
||
412 | public function isVirtual() |
||
416 | } |
||
417 |
If you suppress an error, we recommend checking for the error condition explicitly: