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 FormInterface |
||
39 | */ |
||
40 | protected $form; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $formName; |
||
46 | |||
47 | /** |
||
48 | * @var FormResult |
||
49 | */ |
||
50 | protected $result; |
||
51 | |||
52 | /** |
||
53 | * @var FormObject |
||
54 | */ |
||
55 | private $formObject; |
||
56 | |||
57 | /** |
||
58 | * @var ConditionProcessor |
||
59 | */ |
||
60 | private $conditionProcessor; |
||
61 | |||
62 | /** |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $fieldsActivationChecked = []; |
||
66 | |||
67 | /** |
||
68 | * Current queue, used to prevent infinite loop. |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $fieldsActivationChecking = []; |
||
73 | |||
74 | /** |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $fieldsValidated = []; |
||
78 | |||
79 | /** |
||
80 | * Array of arbitral data which are handled by validators. |
||
81 | * |
||
82 | * @var array |
||
83 | */ |
||
84 | protected $validationData = []; |
||
85 | |||
86 | /** |
||
87 | * @var PhpConditionDataObject |
||
88 | */ |
||
89 | protected $phpConditionDataObject; |
||
90 | |||
91 | /** |
||
92 | * @param FormInterface $form |
||
93 | * @param string $formName |
||
94 | * @param FormResult $result |
||
95 | */ |
||
96 | public function __construct(FormInterface $form, $formName, FormResult $result) |
||
102 | |||
103 | /** |
||
104 | * @return FormValidatorExecutor |
||
105 | */ |
||
106 | public function applyBehaviours() |
||
114 | |||
115 | /** |
||
116 | * This function will take care of deactivating the validation for fields |
||
117 | * that do not match their activation condition. |
||
118 | * |
||
119 | * @return FormValidatorExecutor |
||
120 | */ |
||
121 | public function checkFieldsActivation() |
||
131 | |||
132 | /** |
||
133 | * @param Field $field |
||
134 | */ |
||
135 | protected function checkFieldActivation(Field $field) |
||
157 | |||
158 | /** |
||
159 | * @param Field $field |
||
160 | */ |
||
161 | protected function checkFieldValidationActivation(Field $field) |
||
171 | |||
172 | /** |
||
173 | * @param callable $callback |
||
174 | * @return FormValidatorExecutor |
||
175 | */ |
||
176 | public function validateFields(callable $callback = null) |
||
190 | |||
191 | /** |
||
192 | * Will loop on each validation rule and apply it of the field. |
||
193 | * Errors are stored in `$this->result`. |
||
194 | * |
||
195 | * @param Field $field |
||
196 | */ |
||
197 | public function validateField(Field $field) |
||
221 | |||
222 | /** |
||
223 | * @param Field $field |
||
224 | * @param Validation $validation |
||
225 | * @return Result |
||
226 | */ |
||
227 | protected function processFieldValidation(Field $field, Validation $validation) |
||
260 | |||
261 | /** |
||
262 | * @return FormResult |
||
263 | */ |
||
264 | public function getResult() |
||
268 | |||
269 | /** |
||
270 | * @param Field $field |
||
271 | * @return bool |
||
272 | */ |
||
273 | protected function getFieldActivationProcessResult(Field $field) |
||
279 | |||
280 | /** |
||
281 | * @param Validation $validation |
||
282 | * @return bool |
||
283 | */ |
||
284 | protected function getValidationActivationProcessResult(Validation $validation) |
||
290 | |||
291 | /** |
||
292 | * @param Field $field |
||
293 | * @return bool |
||
294 | */ |
||
295 | protected function fieldActivationHasBeenChecked(Field $field) |
||
299 | |||
300 | /** |
||
301 | * @param Field $field |
||
302 | */ |
||
303 | protected function markFieldActivationAsChecked(Field $field) |
||
307 | |||
308 | /** |
||
309 | * @param Field $field |
||
310 | * @return bool |
||
311 | */ |
||
312 | protected function fieldActivationIsBeingChecked(Field $field) |
||
316 | |||
317 | /** |
||
318 | * @param Field $field |
||
319 | */ |
||
320 | protected function markFieldActivationCheckBegin(Field $field) |
||
324 | |||
325 | /** |
||
326 | * @param Field $field |
||
327 | */ |
||
328 | protected function markFieldActivationCheckEnd(Field $field) |
||
332 | |||
333 | /** |
||
334 | * @param Field $field |
||
335 | * @return bool |
||
336 | */ |
||
337 | protected function fieldWasValidated(Field $field) |
||
341 | |||
342 | /** |
||
343 | * @param Field $field |
||
344 | */ |
||
345 | protected function markFieldAsValidated(Field $field) |
||
349 | |||
350 | /** |
||
351 | * @return FormObject |
||
352 | */ |
||
353 | public function getFormObject() |
||
364 | |||
365 | /** |
||
366 | * @return ConditionProcessor |
||
367 | */ |
||
368 | protected function getConditionProcessor() |
||
376 | |||
377 | /** |
||
378 | * @return PhpConditionDataObject |
||
379 | */ |
||
380 | protected function getPhpConditionDataObject() |
||
388 | } |
||
389 |
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.