| Conditions | 1 |
| Paths | 1 |
| Total Lines | 90 |
| Code Lines | 78 |
| 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 |
||
| 79 | public function Form() |
||
| 80 | { |
||
| 81 | $array = array(); |
||
| 82 | $array[] = "green"; |
||
| 83 | $array[] = "yellow"; |
||
| 84 | $array[] = "blue"; |
||
| 85 | $array[] = "pink"; |
||
| 86 | $array[] = "orange"; |
||
| 87 | $errorField0 = new TextField($name = "ErrorField0", $title = "Text Field Example 1"); |
||
| 88 | $errorField0->setError("message shown when something is good", "good"); |
||
| 89 | $errorField1 = new TextField($name = "ErrorField1", $title = "Text Field Example 2"); |
||
| 90 | $errorField1->setError("message shown when something is bad", "bad"); |
||
| 91 | $errorField2 = new TextField($name = "ErrorField2", $title = "Text Field Example 3"); |
||
| 92 | $errorField2->setCustomValidationMessage("message shown when something is bad", "bad"); |
||
| 93 | $errorField3 = new TextField($name = "ErrorField3", $title = "Text Field Example 4"); |
||
| 94 | $errorField3->setError("there is an error", "required"); |
||
| 95 | $errorField4 = new TextField($name = "ErrorField4", $title = "Text Field Example 5"); |
||
| 96 | $errorField4->setCustomValidationMessage("custom validation error"); |
||
| 97 | $rightTitle = new TextField($name = "RightTitleField", $title = "Left Title is Default"); |
||
| 98 | $rightTitle->setRightTitle("right title here"); |
||
| 99 | $readonlyField = new ReadOnlyField($name = "ReadOnlyField", $title = "ReadOnlyField"); |
||
| 100 | $readonlyField->setValue("read only value"); |
||
| 101 | $groupedDropdownField = new GroupedDropdownField( |
||
| 102 | $name = "dropdown", |
||
| 103 | $title = "Simple Grouped Dropdown", |
||
| 104 | $source = array( |
||
| 105 | "primary" => array( |
||
| 106 | "1" => "Green", |
||
| 107 | "2" => "Red", |
||
| 108 | "3" => "Blue", |
||
| 109 | "4" => "Orange" |
||
| 110 | ), |
||
| 111 | "secondary" => array( |
||
| 112 | "11" => "Light Blue", |
||
| 113 | "12" => "Dark Brown", |
||
| 114 | "13" => "Pinkish Red" |
||
| 115 | ) |
||
| 116 | ) |
||
| 117 | ); |
||
| 118 | $formClassName = Config::inst()->get("TypographyTestPage_Controller", "form_class_name"); |
||
| 119 | $form = $formClassName::create( |
||
| 120 | $controller = $this, |
||
| 121 | $name = "TestForm", |
||
| 122 | $fields = new FieldList( |
||
| 123 | // List the your fields here |
||
| 124 | new HeaderField($name = "HeaderField1", $title = "Default Header Field"), |
||
| 125 | new LiteralField($name = "LiteralField", "<p>NOTE: All fields up to EmailField are required and should be marked as such</p>"), |
||
| 126 | new TextField($name = "TextField1", $title = "Text Field Example 1"), |
||
| 127 | new TextField($name = "TextField2", $title = "Text Field Example 2"), |
||
| 128 | new TextField($name = "TextField3", $title = "Text Field Example 3"), |
||
| 129 | new TextField($name = "TextField4", $title = ""), |
||
| 130 | new HeaderField($name = "HeaderField2a", $title = "Error Messages", 2), |
||
| 131 | new LiteralField($name = "ErrorExplanations", '<p>Below are some error messages, some of them only show up after you have placed your cursor on the field and not completed it (i.e. a reminder to complete the field)</p>'), |
||
| 132 | $errorField0, |
||
| 133 | $errorField1, |
||
| 134 | $errorField2, |
||
| 135 | $errorField3, |
||
| 136 | $errorField4, |
||
| 137 | new HeaderField($name = "HeaderField2b", $title = "Field with right title", 2), |
||
| 138 | $rightTitle, |
||
| 139 | $textAreaField = new TextareaField($name = "TextareaField", $title = "Textarea Field"), |
||
| 140 | new EmailField("EmailField", "Email address"), |
||
| 141 | new HeaderField($name = "HeaderField2c", $title = "HeaderField Level 2", 2), |
||
| 142 | new DropdownField($name = "DropdownField", $title = "Dropdown Field", array( 0 => "-- please select --", 1 => "test AAAA", 2 => "test BBBB")), |
||
| 143 | new OptionsetField($name = "OptionsetField", $title = "Optionset Field", $array), |
||
| 144 | new CheckboxSetField($name = "CheckboxSetField", $title = "Checkbox Set Field", $array), |
||
| 145 | new CurrencyField($name = "CurrencyField", $title = "Bling bling"), |
||
| 146 | new HeaderField($name = "HeaderField3", $title = "Other Fields", 3), |
||
| 147 | new NumericField($name = "NumericField", $title = "Numeric Field "), |
||
| 148 | new DateField($name = "DateField", $title = "Date Field"), |
||
| 149 | new DateField($name = "DateTimeField", $title = "Date and Time Field"), |
||
| 150 | new FileField($name = "FileField", $title = "File Field"), |
||
| 151 | new ConfirmedPasswordField($name = "ConfirmPasswordField", $title = "Password"), |
||
| 152 | new CheckboxField($name = "CheckboxField", $title = "Checkbox Field"), |
||
| 153 | $groupedDropdownField, |
||
| 154 | new HeaderField($name = "HeaderField4", $title = "Read-only Field", 3), |
||
| 155 | $readonlyField |
||
| 156 | ), |
||
| 157 | $actions = new FieldList( |
||
| 158 | // List the action buttons here |
||
| 159 | new FormAction("signup", "Sign up") |
||
| 160 | ), |
||
| 161 | $requiredFields = new RequiredFields( |
||
| 162 | "TextField1", "TextField2", "TextField3", "ErrorField1", "ErrorField2", "EmailField", "TextField3", "RightTitleField", "CheckboxField", "CheckboxSetField" |
||
| 163 | ) |
||
| 164 | ); |
||
| 165 | $textAreaField->setColumns(7); |
||
| 166 | $form->setMessage("warning message", "warning"); |
||
| 167 | return $form; |
||
| 168 | } |
||
| 169 | |||
| 210 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.