Complex classes like FormValidatorExecutor 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 FormValidatorExecutor, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
33 | class FormValidatorExecutor |
||
34 | { |
||
35 | /** |
||
36 | * @var FormObject |
||
37 | */ |
||
38 | protected $formObject; |
||
39 | |||
40 | /** |
||
41 | * @var ConditionProcessor |
||
42 | */ |
||
43 | private $conditionProcessor; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $fieldsActivationChecked = []; |
||
49 | |||
50 | /** |
||
51 | * Current queue, used to prevent infinite loop. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $fieldsActivationChecking = []; |
||
56 | |||
57 | /** |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $fieldsValidated = []; |
||
61 | |||
62 | /** |
||
63 | * Array of arbitral data which are handled by validators. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $validationData = []; |
||
68 | |||
69 | /** |
||
70 | * @var PhpConditionDataObject |
||
71 | */ |
||
72 | protected $phpConditionDataObject; |
||
73 | |||
74 | /** |
||
75 | * @param FormObject $formObject |
||
76 | */ |
||
77 | public function __construct(FormObject $formObject) |
||
83 | |||
84 | /** |
||
85 | * @return FormValidatorExecutor |
||
86 | */ |
||
87 | public function applyBehaviours() |
||
95 | |||
96 | /** |
||
97 | * This function will take care of deactivating the validation for fields |
||
98 | * that do not match their activation condition. |
||
99 | * |
||
100 | * @return FormValidatorExecutor |
||
101 | */ |
||
102 | public function checkFieldsActivation() |
||
112 | |||
113 | /** |
||
114 | * @param Field $field |
||
115 | */ |
||
116 | protected function checkFieldActivation(Field $field) |
||
138 | |||
139 | /** |
||
140 | * @param Field $field |
||
141 | */ |
||
142 | protected function checkFieldValidatorActivation(Field $field) |
||
152 | |||
153 | /** |
||
154 | * @param callable $callback |
||
155 | * @return FormValidatorExecutor |
||
156 | */ |
||
157 | public function validateFields(callable $callback = null) |
||
171 | |||
172 | /** |
||
173 | * Will loop on each validator and apply it on the field. The validation |
||
174 | * result is merged with the form result. |
||
175 | * |
||
176 | * @param Field $field |
||
177 | */ |
||
178 | public function validateField(Field $field) |
||
202 | |||
203 | /** |
||
204 | * @param Field $field |
||
205 | * @param Validator $validator |
||
206 | * @return Result |
||
207 | */ |
||
208 | protected function processFieldValidator(Field $field, Validator $validator) |
||
242 | |||
243 | /** |
||
244 | * @return FormResult |
||
245 | */ |
||
246 | public function getResult() |
||
250 | |||
251 | /** |
||
252 | * @param Field $field |
||
253 | * @return bool |
||
254 | */ |
||
255 | protected function getFieldActivationProcessResult(Field $field) |
||
259 | |||
260 | /** |
||
261 | * @param Validator $validator |
||
262 | * @return bool |
||
263 | */ |
||
264 | protected function getValidatorActivationProcessResult(Validator $validator) |
||
268 | |||
269 | /** |
||
270 | * @param Field $field |
||
271 | * @return bool |
||
272 | */ |
||
273 | protected function fieldActivationHasBeenChecked(Field $field) |
||
277 | |||
278 | /** |
||
279 | * @param Field $field |
||
280 | */ |
||
281 | protected function markFieldActivationAsChecked(Field $field) |
||
285 | |||
286 | /** |
||
287 | * @param Field $field |
||
288 | * @return bool |
||
289 | */ |
||
290 | protected function fieldActivationIsBeingChecked(Field $field) |
||
294 | |||
295 | /** |
||
296 | * @param Field $field |
||
297 | */ |
||
298 | protected function markFieldActivationCheckBegin(Field $field) |
||
302 | |||
303 | /** |
||
304 | * @param Field $field |
||
305 | */ |
||
306 | protected function markFieldActivationCheckEnd(Field $field) |
||
310 | |||
311 | /** |
||
312 | * @param Field $field |
||
313 | * @return bool |
||
314 | */ |
||
315 | protected function fieldWasValidated(Field $field) |
||
319 | |||
320 | /** |
||
321 | * @param Field $field |
||
322 | */ |
||
323 | protected function markFieldAsValidated(Field $field) |
||
327 | |||
328 | /** |
||
329 | * @return ConditionProcessor |
||
330 | */ |
||
331 | protected function getConditionProcessor() |
||
335 | |||
336 | /** |
||
337 | * @return PhpConditionDataObject |
||
338 | */ |
||
339 | protected function getPhpConditionDataObject() |
||
343 | } |
||
344 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.