| Conditions | 16 |
| Paths | 32 |
| Total Lines | 55 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 14 | public static function add_explanations($form, $datarecord) |
||
| 15 | { |
||
| 16 | $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
||
| 17 | $js = ' |
||
| 18 | var formFieldExplanationErrorMessage = new Array();'; |
||
| 19 | $dos = DataObject::get("FormFieldExplanation", "{$bt}ParentID{$bt} = ".$datarecord->ID); |
||
| 20 | $explanations = array(); |
||
| 21 | if ($dos) { |
||
| 22 | foreach ($dos as $do) { |
||
| 23 | if ($do->Explanation) { |
||
| 24 | $explanations[$do->Name]["Explanation"] = $do->Explanation; |
||
| 25 | } |
||
| 26 | if ($do->CustomErrorMessage) { |
||
| 27 | $explanations[$do->Name]["CustomErrorMessage"] = $do->CustomErrorMessage; |
||
| 28 | } |
||
| 29 | if ($do->CustomErrorMessageAdditional) { |
||
| 30 | $explanations[$do->Name]["CustomErrorMessageAdditional"] = $do->CustomErrorMessageAdditional; |
||
| 31 | } |
||
| 32 | if ($do->AlternativeFieldLabel) { |
||
| 33 | $explanations[$do->Name]["AlternativeFieldLabel"] = $do->AlternativeFieldLabel; |
||
| 34 | } |
||
| 35 | if ($do->ID) { |
||
| 36 | $explanations[$do->Name]["ID"] = $do->ID; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | $dos = $do = null; |
||
| 41 | $dataFields = $form->fields(); |
||
| 42 | $extraFields = new FieldSet(); |
||
| 43 | if ($dataFields) { |
||
| 44 | foreach ($dataFields as $field) { |
||
| 45 | if ($field instanceof CompositeField) { |
||
| 46 | self::find_composite_fields($field, $extraFields); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 | if ($dataFields) { |
||
| 51 | foreach ($dataFields as $field) { |
||
| 52 | self::process_field($field, $explanations, $datarecord, $js); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | if ($extraFields) { |
||
| 56 | foreach ($extraFields as $field) { |
||
| 57 | self::process_field($field, $explanations, $datarecord, $js); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | // block prototype validation |
||
| 61 | Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
||
| 62 | Requirements::block("sapphire/javascript/Validator.js"); |
||
| 63 | Requirements::javascript("formfieldexplanations/javascript/Silvertripe-2.3-Validator.js"); |
||
| 64 | Requirements::javascript("formfieldexplanations/javascript/formfieldexplanations.js"); |
||
| 65 | Requirements::customScript($js, "FormFieldExplanationExtension"); |
||
| 66 | Requirements::themedCSS("formfieldexplanations"); |
||
| 67 | return $form; |
||
| 68 | } |
||
| 69 | |||
| 201 |