Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 47 |
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 |
||
52 | $data = new ArrayData([ |
||
53 | 'Title' => 'Styleguide', |
||
54 | 'Message' => DBField::create_field( |
||
55 | 'HTMLText', |
||
56 | '<p>This controller is only accessible to developers and admin users.</p>' |
||
57 | ), |
||
58 | 'TestForm' => $this->getTestForm(), |
||
59 | 'Content' => $this->getContent(), |
||
60 | 'ColorSwatches' => $this->getColorSwatches(), |
||
61 | ]); |
||
62 | |||
63 | // extensions for adding/overriding template data. |
||
64 | $this->extend('updateStyleguideData', $data); |
||
65 | |||
66 | return $data; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Return a form with fields to match rendering through controller/template output. |
||
71 | * @return Form |
||
72 | */ |
||
73 | public function getTestForm() |
||
74 | { |
||
75 | $fields = FieldList::create( |
||
76 | TextField::create('SimpleText', 'Simple Text Field'), |
||
77 | TextField::create('SimpleTextGood', 'Simple Text Field (good)') |
||
78 | ->setError('This is a good message', 'good'), |
||
79 | TextField::create('SimpleTextWarning', 'Simple Text Field (warning)') |
||
80 | ->setError('This is a warning message', 'warning'), |
||
81 | TextField::create('SimpleTextBad', 'Simple Text Field (bad)') |
||
82 | ->setError('This is an error message', 'bad'), |
||
83 | NumericField::create('Number', 'Number Field'), |
||
84 | EmailField::create('Email', "Email Field"), |
||
85 | DropdownField::create('Dropdown', 'Normal dropdown', [ |
||
86 | '1' => 'One option', |
||
87 | '2' => 'Two option', |
||
88 | ]), |
||
89 | CheckboxField::create('Checkbox', 'Checkbox'), |
||
90 | CheckboxSetField::create('CheckboxSet', 'Checkbox set', [ |
||
91 | '1' => 'One option', |
||
92 | '2' => 'Two option', |
||
93 | '3' => 'Three option', |
||
94 | ]), |
||
95 | OptionsetField::create('Option', 'Option', [ |
||
96 | '1' => 'One option', |
||
97 | ]), |
||
98 | OptionsetField::create('OptionSet', 'Option set', [ |
||
99 | '1' => 'One option', |
||
100 | '2' => 'Two option', |
||
101 | '3' => 'Three option', |
||
102 | ]), |
||
103 | TextField::create('Text', 'Text') |
||
104 | ->setDescription('This is a description') |
||
105 | ); |
||
106 | |||
107 | $actions = FieldList::create( |
||
108 | FormAction::create('doForm', 'Submit') |
||
109 | ); |
||
110 | |||
111 | $required = new RequiredFields( |
||
112 | 'SimpleText', |
||
113 | 'Email', |
||
114 | 'Checkbox', |
||
115 | 'Dropdown' |
||
116 | ); |
||
117 | |||
161 |
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.