| Conditions | 1 |
| Paths | 1 |
| Total Lines | 192 |
| Code Lines | 122 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 229 | protected function setupCreateOperation() |
||
| 230 | { |
||
| 231 | CRUD::setValidation(StoreRequest::class); |
||
| 232 | |||
| 233 | CRUD::addFields([ |
||
| 234 | [ |
||
| 235 | // RYTHM |
||
| 236 | 'label' => __('Partnership'), |
||
| 237 | 'type' => 'select', |
||
| 238 | 'name' => 'partner_id', |
||
| 239 | 'entity' => 'partner', |
||
| 240 | 'attribute' => 'name', |
||
| 241 | 'model' => Partner::class, |
||
| 242 | 'tab' => __('Course info'), |
||
| 243 | ], |
||
| 244 | |||
| 245 | [ |
||
| 246 | // RYTHM |
||
| 247 | 'label' => __('Rhythm'), |
||
| 248 | 'type' => 'select', |
||
| 249 | 'name' => 'rhythm_id', |
||
| 250 | 'entity' => 'rhythm', |
||
| 251 | 'attribute' => 'name', |
||
| 252 | 'model' => Rhythm::class, |
||
| 253 | 'tab' => __('Course info'), |
||
| 254 | ], |
||
| 255 | |||
| 256 | [ |
||
| 257 | // LEVEL |
||
| 258 | 'label' => __('Level'), |
||
| 259 | 'type' => 'select', |
||
| 260 | 'name' => 'level_id', |
||
| 261 | 'entity' => 'level', |
||
| 262 | 'attribute' => 'name', |
||
| 263 | 'model' => Level::class, |
||
| 264 | 'tab' => __('Course info'), |
||
| 265 | ], |
||
| 266 | |||
| 267 | [ |
||
| 268 | 'name' => 'name', |
||
| 269 | 'label' => __('Name'), |
||
| 270 | 'tab' => __('Course info'), |
||
| 271 | ], |
||
| 272 | |||
| 273 | [ |
||
| 274 | 'name' => 'volume', |
||
| 275 | 'label' => __('Volume'), |
||
| 276 | 'suffix' => 'h', |
||
| 277 | 'tab' => __('Course info'), |
||
| 278 | ], |
||
| 279 | |||
| 280 | [ |
||
| 281 | 'name' => 'hourly_price', |
||
| 282 | 'label' => __('Hourly Price'), |
||
| 283 | 'prefix' => '$', |
||
| 284 | 'tab' => __('Course info'), |
||
| 285 | ], |
||
| 286 | |||
| 287 | [ |
||
| 288 | // TEACHER |
||
| 289 | 'label' => __('Teacher'), |
||
| 290 | 'type' => 'select', |
||
| 291 | 'name' => 'teacher_id', |
||
| 292 | 'entity' => 'teacher', |
||
| 293 | 'attribute' => 'name', |
||
| 294 | 'model' => Teacher::class, |
||
| 295 | 'tab' => __('Course info'), |
||
| 296 | ], |
||
| 297 | |||
| 298 | [ |
||
| 299 | // ROOM |
||
| 300 | 'label' => __('Room'), |
||
| 301 | 'type' => 'select', |
||
| 302 | 'name' => 'room_id', |
||
| 303 | 'entity' => 'room', |
||
| 304 | 'attribute' => 'name', |
||
| 305 | 'model' => Room::class, |
||
| 306 | 'tab' => __('Course info'), |
||
| 307 | ], |
||
| 308 | |||
| 309 | [ |
||
| 310 | // RYTHM |
||
| 311 | 'label' => __('Campus'), |
||
| 312 | 'type' => 'hidden', |
||
| 313 | 'name' => 'campus_id', |
||
| 314 | 'value' => 2, |
||
| 315 | 'tab' => __('Course info'), |
||
| 316 | ], |
||
| 317 | |||
| 318 | [ |
||
| 319 | 'name' => 'price', |
||
| 320 | 'type' => 'hidden', |
||
| 321 | 'value' => 0, |
||
| 322 | 'tab' => __('Course info'), |
||
| 323 | ], |
||
| 324 | |||
| 325 | [ |
||
| 326 | // PERIOD |
||
| 327 | 'label' => __('Period'), |
||
| 328 | 'type' => 'select', |
||
| 329 | 'name' => 'period_id', |
||
| 330 | 'entity' => 'period', |
||
| 331 | 'attribute' => 'name', |
||
| 332 | 'model' => Period::class, |
||
| 333 | 'tab' => __('Schedule'), |
||
| 334 | 'default' => Period::get_enrollments_period()->id, |
||
| 335 | ], |
||
| 336 | |||
| 337 | [ |
||
| 338 | 'name' => 'start_date', |
||
| 339 | 'label' => __('Start Date'), |
||
| 340 | 'type' => 'date', |
||
| 341 | 'tab' => __('Schedule'), |
||
| 342 | 'default' => Period::get_enrollments_period()->start, |
||
| 343 | ], |
||
| 344 | |||
| 345 | [ |
||
| 346 | 'name' => 'end_date', |
||
| 347 | 'label' => __('End Date'), |
||
| 348 | 'type' => 'date', |
||
| 349 | 'tab' => __('Schedule'), |
||
| 350 | 'default' => Period::get_enrollments_period()->end, |
||
| 351 | ], |
||
| 352 | |||
| 353 | [ |
||
| 354 | 'name' => 'head_count', |
||
| 355 | 'label' => __('Head Count'), |
||
| 356 | 'type' => 'number', |
||
| 357 | 'tab' => __('Course info'), |
||
| 358 | ], |
||
| 359 | |||
| 360 | [ |
||
| 361 | 'name' => 'new_students', |
||
| 362 | 'label' => __('Students to count in year total'), |
||
| 363 | 'type' => 'number', |
||
| 364 | 'tab' => __('Course info'), |
||
| 365 | ], |
||
| 366 | |||
| 367 | [ // repeatable |
||
| 368 | 'name' => 'times', |
||
| 369 | 'label' => __('Course Schedule'), |
||
| 370 | 'type' => 'repeatable', |
||
| 371 | 'fields' => [ |
||
| 372 | [ |
||
| 373 | 'name' => 'day', |
||
| 374 | 'label' => __('Day'), |
||
| 375 | 'type' => 'select_from_array', |
||
| 376 | 'options' => [ |
||
| 377 | 0 => __('Sunday'), |
||
| 378 | 1 => __('Monday'), |
||
| 379 | 2 => __('Tuesday'), |
||
| 380 | 3 => __('Wednesday'), |
||
| 381 | 4 => __('Thursday'), |
||
| 382 | 5 => __('Friday'), |
||
| 383 | 6 => __('Saturday'), |
||
| 384 | ], |
||
| 385 | 'allows_null' => false, |
||
| 386 | 'default' => 1, |
||
| 387 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
| 388 | ], |
||
| 389 | [ |
||
| 390 | 'name' => 'start', |
||
| 391 | 'type' => 'time', |
||
| 392 | 'label' => __('Start'), |
||
| 393 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
| 394 | ], |
||
| 395 | [ |
||
| 396 | 'name' => 'end', |
||
| 397 | 'type' => 'time', |
||
| 398 | 'label' => __('End'), |
||
| 399 | 'wrapper' => ['class' => 'form-group col-md-4'], |
||
| 400 | ], |
||
| 401 | ], |
||
| 402 | 'init_rows' => 0, |
||
| 403 | 'tab' => __('Schedule'), |
||
| 404 | ], |
||
| 405 | |||
| 406 | [ // view |
||
| 407 | 'name' => 'custom-ajax-button', |
||
| 408 | 'type' => 'view', |
||
| 409 | 'view' => 'courses/schedule-preset-alert', |
||
| 410 | 'tab' => __('Schedule'), |
||
| 411 | ], |
||
| 412 | ]); |
||
| 413 | |||
| 414 | CRUD::addField([ |
||
| 415 | 'name' => 'schedulepreset', |
||
| 416 | 'label' => __('Schedule Preset'), |
||
| 417 | 'type' => 'select_from_array', |
||
| 418 | 'options' => array_column(SchedulePreset::all()->toArray(), 'name', 'presets'), |
||
| 419 | 'allows_null' => true, |
||
| 420 | 'tab' => __('Schedule'), |
||
| 421 | ]); |
||
| 632 |