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 |
||
35 | class FormValidatorExecutor |
||
36 | { |
||
37 | /** |
||
38 | * @var FormValidatorDataObject |
||
39 | */ |
||
40 | protected $dataObject; |
||
41 | |||
42 | /** |
||
43 | * @var ConditionProcessor |
||
44 | */ |
||
45 | private $conditionProcessor; |
||
46 | |||
47 | /** |
||
48 | * @var PhpConditionDataObject |
||
49 | */ |
||
50 | protected $phpConditionDataObject; |
||
51 | |||
52 | /** |
||
53 | * @var SubstepService |
||
54 | */ |
||
55 | protected $substepService; |
||
56 | |||
57 | /** |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $fieldsActivationChecked = []; |
||
61 | |||
62 | /** |
||
63 | * Current queue, used to prevent infinite loop. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $fieldsActivationChecking = []; |
||
68 | |||
69 | /** |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $fieldsValidated = []; |
||
73 | |||
74 | /** |
||
75 | * Array of arbitral data which are handled by validators. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $validationData = []; |
||
80 | |||
81 | /** |
||
82 | * @param FormValidatorDataObject $dataObject |
||
83 | */ |
||
84 | public function __construct(FormValidatorDataObject $dataObject) |
||
93 | |||
94 | /** |
||
95 | * @return FormValidatorExecutor |
||
96 | */ |
||
97 | public function applyBehaviours() |
||
105 | |||
106 | /** |
||
107 | * This function will take care of deactivating the validation for fields |
||
108 | * that do not match their activation condition. |
||
109 | * |
||
110 | * @return FormValidatorExecutor |
||
111 | */ |
||
112 | public function checkFieldsActivation() |
||
122 | |||
123 | /** |
||
124 | * @param Field $field |
||
125 | */ |
||
126 | protected function checkFieldActivation(Field $field) |
||
153 | |||
154 | /** |
||
155 | * Check if the given field is supported by the current step of the form. |
||
156 | * |
||
157 | * @param Field $field |
||
158 | */ |
||
159 | protected function checkFieldStepSupport(Field $field) |
||
169 | |||
170 | /** |
||
171 | * @param Field $field |
||
172 | */ |
||
173 | protected function checkFieldValidatorActivation(Field $field) |
||
183 | |||
184 | /** |
||
185 | * @return FormValidatorExecutor |
||
186 | */ |
||
187 | public function validateFields() |
||
201 | |||
202 | /** |
||
203 | * Will loop on each validator and apply it on the field. The validation |
||
204 | * result is merged with the form result. |
||
205 | * |
||
206 | * @param Field $field |
||
207 | */ |
||
208 | public function validateField(Field $field) |
||
237 | |||
238 | /** |
||
239 | * @param Field $field |
||
240 | * @param Validator $validator |
||
241 | * @return Result |
||
242 | */ |
||
243 | protected function processFieldValidator(Field $field, Validator $validator) |
||
277 | |||
278 | /** |
||
279 | * Loops on registered callbacks that should be called after the given field |
||
280 | * validation. |
||
281 | * |
||
282 | * @param Field $field |
||
283 | */ |
||
284 | protected function callFieldValidationCallback(Field $field) |
||
294 | |||
295 | /** |
||
296 | * @return FormObject |
||
297 | */ |
||
298 | public function getFormObject() |
||
302 | |||
303 | /** |
||
304 | * @return FormResult |
||
305 | */ |
||
306 | public function getResult() |
||
310 | |||
311 | /** |
||
312 | * @param Field $field |
||
313 | * @return bool |
||
314 | */ |
||
315 | protected function getFieldActivationProcessResult(Field $field) |
||
319 | |||
320 | /** |
||
321 | * @param Validator $validator |
||
322 | * @return bool |
||
323 | */ |
||
324 | protected function getValidatorActivationProcessResult(Validator $validator) |
||
328 | |||
329 | /** |
||
330 | * @param Field $field |
||
331 | * @return bool |
||
332 | */ |
||
333 | protected function fieldActivationHasBeenChecked(Field $field) |
||
337 | |||
338 | /** |
||
339 | * @param Field $field |
||
340 | */ |
||
341 | protected function markFieldActivationAsChecked(Field $field) |
||
345 | |||
346 | /** |
||
347 | * @param Field $field |
||
348 | * @return bool |
||
349 | */ |
||
350 | protected function fieldActivationIsBeingChecked(Field $field) |
||
354 | |||
355 | /** |
||
356 | * @param Field $field |
||
357 | */ |
||
358 | protected function markFieldActivationCheckBegin(Field $field) |
||
362 | |||
363 | /** |
||
364 | * @param Field $field |
||
365 | */ |
||
366 | protected function markFieldActivationCheckEnd(Field $field) |
||
370 | |||
371 | /** |
||
372 | * @param Field $field |
||
373 | * @return bool |
||
374 | */ |
||
375 | protected function fieldWasValidated(Field $field) |
||
379 | |||
380 | /** |
||
381 | * @param Field $field |
||
382 | */ |
||
383 | protected function markFieldAsValidated(Field $field) |
||
387 | |||
388 | /** |
||
389 | * @return ConditionProcessor |
||
390 | */ |
||
391 | protected function getConditionProcessor() |
||
395 | |||
396 | /** |
||
397 | * @return PhpConditionDataObject |
||
398 | */ |
||
399 | protected function getPhpConditionDataObject() |
||
403 | } |
||
404 |
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.