Conditions | 1 |
Paths | 1 |
Total Lines | 100 |
Code Lines | 87 |
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 |
||
6 | public function __construct($controller, $nameOfForm = 'TestForm') |
||
7 | { |
||
8 | $array = array(); |
||
9 | $array[] = "green"; |
||
10 | $array[] = "yellow"; |
||
11 | $array[] = "blue"; |
||
12 | $array[] = "pink"; |
||
13 | $array[] = "orange"; |
||
14 | $errorField0 = new TextField($name = "ErrorField0", $title = "Text Field Example 1"); |
||
15 | $errorField0->setError("message shown when something is good", "good"); |
||
16 | $errorField1 = new TextField($name = "ErrorField1", $title = "Text Field Example 2"); |
||
17 | $errorField1->setError("message shown when something is bad", "bad"); |
||
18 | $errorField2 = new TextField($name = "ErrorField2", $title = "Text Field Example 3"); |
||
19 | $errorField2->setCustomValidationMessage("message shown when something is bad", "bad"); |
||
20 | $errorField3 = new TextField($name = "ErrorField3", $title = "Text Field Example 4"); |
||
21 | $errorField3->setError("there is an error", "required"); |
||
22 | $errorField4 = new TextField($name = "ErrorField4", $title = "Text Field Example 5"); |
||
23 | $errorField4->setCustomValidationMessage("custom validation error"); |
||
24 | $rightTitle = new TextField($name = "RightTitleField", $title = "Left Title is Default"); |
||
25 | $rightTitle->setRightTitle("right title here"); |
||
26 | $readonlyField = new ReadOnlyField($name = "ReadOnlyField", $title = "ReadOnlyField"); |
||
27 | $readonlyField->setValue("read only value"); |
||
28 | $groupedDropdownField = new GroupedDropdownField( |
||
29 | $name = "dropdown", |
||
30 | $title = "Simple Grouped Dropdown", |
||
31 | $source = array( |
||
32 | "primary" => array( |
||
33 | "1" => "Green", |
||
34 | "2" => "Red", |
||
35 | "3" => "Blue", |
||
36 | "4" => "Orange" |
||
37 | ), |
||
38 | "secondary" => array( |
||
39 | "11" => "Light Blue", |
||
40 | "12" => "Dark Brown", |
||
41 | "13" => "Pinkish Red" |
||
42 | ) |
||
43 | ) |
||
44 | ); |
||
45 | $returnResult = parent::__construct( |
||
46 | $controller, |
||
47 | $nameOfForm, |
||
48 | $fields = new FieldList( |
||
49 | // List the your fields here |
||
50 | new LiteralField($name = "HeaderFieldForForm", $title = '<h1 id="Form">Form Elements</h1>'), |
||
51 | new HeaderField($name = "HeaderField1", $title = "Default Header Field"), |
||
52 | new LiteralField($name = "LiteralField", "<p>NOTE: All fields up to EmailField are required and should be marked as such</p>"), |
||
53 | new TextField($name = "TextField1", $title = "Text Field Example 1"), |
||
54 | new TextField($name = "TextField2", $title = "Text Field Example 2"), |
||
55 | new TextField($name = "TextField3", $title = "Text Field Example 3"), |
||
56 | new TextField($name = "TextField4", $title = ""), |
||
57 | new HeaderField($name = "HeaderField2a", $title = "Error Messages", 2), |
||
58 | 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>'), |
||
59 | $errorField0, |
||
60 | $errorField1, |
||
61 | $errorField2, |
||
62 | $errorField3, |
||
63 | $errorField4, |
||
64 | new HeaderField($name = "HeaderField2b", $title = "Field with right title", 2), |
||
65 | $rightTitle, |
||
66 | $textAreaField = new TextareaField($name = "TextareaField", $title = "Textarea Field"), |
||
67 | new EmailField("EmailField", "Email address"), |
||
68 | new HeaderField($name = "HeaderField2c", $title = "HeaderField Level 2", 2), |
||
69 | new DropdownField($name = "DropdownField", $title = "Dropdown Field", array( 0 => "-- please select --", 1 => "test AAAA", 2 => "test BBBB")), |
||
70 | new OptionsetField($name = "OptionsetField", $title = "Optionset Field", $array), |
||
71 | new CheckboxSetField($name = "CheckboxSetField", $title = "Checkbox Set Field", $array), |
||
72 | new CurrencyField($name = "CurrencyField", $title = "Bling bling"), |
||
73 | new HeaderField($name = "HeaderField3", $title = "Other Fields", 3), |
||
74 | new NumericField($name = "NumericField", $title = "Numeric Field "), |
||
75 | new DateField($name = "DateField", $title = "Date Field"), |
||
76 | new DateField($name = "DateTimeField", $title = "Date and Time Field"), |
||
77 | new FileField($name = "FileField", $title = "File Field"), |
||
78 | new ConfirmedPasswordField($name = "ConfirmPasswordField", $title = "Password"), |
||
79 | new CheckboxField($name = "CheckboxField", $title = "Checkbox Field"), |
||
80 | $groupedDropdownField, |
||
81 | new HeaderField($name = "HeaderField4", $title = "Read-only Field", 3), |
||
82 | $readonlyField |
||
83 | ), |
||
84 | $actions = new FieldList( |
||
85 | // List the action buttons here |
||
86 | new FormAction("signup", "Sign up") |
||
87 | ), |
||
88 | $requiredFields = new RequiredFields( |
||
89 | "TextField1", |
||
90 | "TextField2", |
||
91 | "TextField3", |
||
92 | "ErrorField1", |
||
93 | "ErrorField2", |
||
94 | "EmailField", |
||
95 | "TextField3", |
||
96 | "RightTitleField", |
||
97 | "CheckboxField", |
||
98 | "CheckboxSetField" |
||
99 | ) |
||
100 | ); |
||
101 | $textAreaField->setColumns(7); |
||
102 | $this->setMessage("warning message", "warning"); |
||
103 | |||
104 | return $returnResult; |
||
105 | } |
||
106 | } |
||
107 |
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.