| Conditions | 1 |
| Paths | 1 |
| Total Lines | 187 |
| Code Lines | 154 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 143 | public function testGetNestedSchema() { |
||
| 144 | $form = new Form( |
||
| 145 | new Controller(), |
||
| 146 | 'TestForm', |
||
| 147 | new FieldList(new TextField("Name")), |
||
| 148 | new FieldList( |
||
| 149 | (new FormAction("save", "Save")) |
||
| 150 | ->setIcon('save'), |
||
| 151 | (new FormAction("cancel", "Cancel")) |
||
| 152 | ->setUseButtonTag(true), |
||
| 153 | new PopoverField("More options", [ |
||
| 154 | new FormAction("publish", "Publish record"), |
||
| 155 | new FormAction("archive", "Archive"), |
||
| 156 | ]) |
||
| 157 | ) |
||
| 158 | ); |
||
| 159 | $formSchema = new FormSchema(); |
||
| 160 | $expected = [ |
||
| 161 | 'name' => 'TestForm', |
||
| 162 | 'id' => 'Form_TestForm', |
||
| 163 | 'action' => 'Controller/TestForm', |
||
| 164 | 'method' => 'POST', |
||
| 165 | 'schema_url' => '', |
||
| 166 | 'attributes' => [ |
||
| 167 | 'id' => 'Form_TestForm', |
||
| 168 | 'action' => 'Controller/TestForm', |
||
| 169 | 'method' => 'POST', |
||
| 170 | 'enctype' => 'application/x-www-form-urlencoded', |
||
| 171 | 'target' => null, |
||
| 172 | 'class' => '' |
||
| 173 | ], |
||
| 174 | 'data' => [], |
||
| 175 | 'fields' => [ |
||
| 176 | [ |
||
| 177 | 'id' => 'Form_TestForm_Name', |
||
| 178 | 'name' => 'Name', |
||
| 179 | 'type' => 'Text', |
||
| 180 | 'component' => null, |
||
| 181 | 'holder_id' => 'Form_TestForm_Name_Holder', |
||
| 182 | 'title' => 'Name', |
||
| 183 | 'source' => null, |
||
| 184 | 'extraClass' => 'text', |
||
| 185 | 'description' => null, |
||
| 186 | 'rightTitle' => null, |
||
| 187 | 'leftTitle' => null, |
||
| 188 | 'readOnly' => false, |
||
| 189 | 'disabled' => false, |
||
| 190 | 'customValidationMessage' => '', |
||
| 191 | 'attributes' => [], |
||
| 192 | 'data' => [], |
||
| 193 | ], |
||
| 194 | [ |
||
| 195 | 'id' => 'Form_TestForm_SecurityID', |
||
| 196 | 'name' => 'SecurityID', |
||
| 197 | 'type' => "Hidden", |
||
| 198 | 'component' => null, |
||
| 199 | 'holder_id' => 'Form_TestForm_SecurityID_Holder', |
||
| 200 | 'title' => 'Security ID', |
||
| 201 | 'source' => null, |
||
| 202 | 'extraClass' => 'hidden', |
||
| 203 | 'description' => null, |
||
| 204 | 'rightTitle' => null, |
||
| 205 | 'leftTitle' => null, |
||
| 206 | 'readOnly' => false, |
||
| 207 | 'disabled' => false, |
||
| 208 | 'customValidationMessage' => '', |
||
| 209 | 'attributes' => [], |
||
| 210 | 'data' => [] |
||
| 211 | ], |
||
| 212 | ], |
||
| 213 | 'actions' => [ |
||
| 214 | [ |
||
| 215 | 'id' => 'Form_TestForm_action_save', |
||
| 216 | 'title' => 'Save', |
||
| 217 | 'name' => 'action_save', |
||
| 218 | 'type' => null, |
||
| 219 | 'component' => 'FormAction', |
||
| 220 | 'holder_id' => 'Form_TestForm_action_save_Holder', |
||
| 221 | 'source' => null, |
||
| 222 | 'extraClass' => 'action', |
||
| 223 | 'description' => null, |
||
| 224 | 'rightTitle' => null, |
||
| 225 | 'leftTitle' => null, |
||
| 226 | 'readOnly' => false, |
||
| 227 | 'disabled' => false, |
||
| 228 | 'customValidationMessage' => '', |
||
| 229 | 'attributes' => [ |
||
| 230 | 'type' => 'submit', |
||
| 231 | ], |
||
| 232 | 'data' => [ |
||
| 233 | 'icon' => 'save', |
||
| 234 | ], |
||
| 235 | ], |
||
| 236 | [ |
||
| 237 | 'id' => 'Form_TestForm_action_cancel', |
||
| 238 | 'title' => 'Cancel', |
||
| 239 | 'name' => 'action_cancel', |
||
| 240 | 'type' => null, |
||
| 241 | 'component' => 'FormAction', |
||
| 242 | 'holder_id' => 'Form_TestForm_action_cancel_Holder', |
||
| 243 | 'source' => null, |
||
| 244 | 'extraClass' => 'action', |
||
| 245 | 'description' => null, |
||
| 246 | 'rightTitle' => null, |
||
| 247 | 'leftTitle' => null, |
||
| 248 | 'readOnly' => false, |
||
| 249 | 'disabled' => false, |
||
| 250 | 'customValidationMessage' => '', |
||
| 251 | 'attributes' => [ |
||
| 252 | 'type' => 'button' |
||
| 253 | ], |
||
| 254 | 'data' => [ |
||
| 255 | 'icon' => null |
||
| 256 | ], |
||
| 257 | ], |
||
| 258 | [ |
||
| 259 | 'id' => 'Form_TestForm_Moreoptions', |
||
| 260 | 'title' => 'More options', |
||
| 261 | 'name' => 'Moreoptions', |
||
| 262 | 'type' => 'Structural', |
||
| 263 | 'component' => 'PopoverField', |
||
| 264 | 'holder_id' => 'Form_TestForm_Moreoptions_Holder', |
||
| 265 | 'source' => null, |
||
| 266 | 'extraClass' => 'field CompositeField popover', |
||
| 267 | 'description' => null, |
||
| 268 | 'rightTitle' => null, |
||
| 269 | 'leftTitle' => null, |
||
| 270 | 'readOnly' => null, |
||
| 271 | 'disabled' => false, |
||
| 272 | 'customValidationMessage' => '', |
||
| 273 | 'attributes' => [], |
||
| 274 | 'data' => [], |
||
| 275 | 'children' => [ |
||
| 276 | [ |
||
| 277 | 'id' => 'Form_TestForm_action_publish', |
||
| 278 | 'title' => 'Publish record', |
||
| 279 | 'name' => 'action_publish', |
||
| 280 | 'type' => null, |
||
| 281 | 'component' => 'FormAction', |
||
| 282 | 'holder_id' => 'Form_TestForm_action_publish_Holder', |
||
| 283 | 'source' => null, |
||
| 284 | 'extraClass' => 'action', |
||
| 285 | 'description' => null, |
||
| 286 | 'rightTitle' => null, |
||
| 287 | 'leftTitle' => null, |
||
| 288 | 'readOnly' => false, |
||
| 289 | 'disabled' => false, |
||
| 290 | 'customValidationMessage' => '', |
||
| 291 | 'attributes' => [ |
||
| 292 | 'type' => 'submit', |
||
| 293 | ], |
||
| 294 | 'data' => [ |
||
| 295 | 'icon' => null, |
||
| 296 | ], |
||
| 297 | ], |
||
| 298 | [ |
||
| 299 | 'id' => 'Form_TestForm_action_archive', |
||
| 300 | 'title' => 'Archive', |
||
| 301 | 'name' => 'action_archive', |
||
| 302 | 'type' => null, |
||
| 303 | 'component' => 'FormAction', |
||
| 304 | 'holder_id' => 'Form_TestForm_action_archive_Holder', |
||
| 305 | 'source' => null, |
||
| 306 | 'extraClass' => 'action', |
||
| 307 | 'description' => null, |
||
| 308 | 'rightTitle' => null, |
||
| 309 | 'leftTitle' => null, |
||
| 310 | 'readOnly' => false, |
||
| 311 | 'disabled' => false, |
||
| 312 | 'customValidationMessage' => '', |
||
| 313 | 'attributes' => [ |
||
| 314 | 'type' => 'submit', |
||
| 315 | ], |
||
| 316 | 'data' => [ |
||
| 317 | 'icon' => null, |
||
| 318 | ], |
||
| 319 | ], |
||
| 320 | ] |
||
| 321 | ] |
||
| 322 | ] |
||
| 323 | ]; |
||
| 324 | |||
| 325 | $schema = $formSchema->getSchema($form); |
||
| 326 | |||
| 327 | $this->assertInternalType('array', $schema); |
||
| 328 | $this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($schema)); |
||
| 329 | } |
||
| 330 | } |
||
| 331 |