| Conditions | 4 |
| Paths | 2 |
| Total Lines | 66 |
| Code Lines | 42 |
| 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 |
||
| 70 | public function getEditForm($id = null, $fields = null) |
||
| 71 | { |
||
| 72 | $form = parent::getEditForm($id, $fields); |
||
| 73 | |||
| 74 | $filter = $this->jobQueue->getJobListFilter(null, 300); |
||
| 75 | |||
| 76 | $list = DataList::create('SilverStripe\\QueuedJobs\\DataObjects\\QueuedJobDescriptor'); |
||
| 77 | $list = $list->where($filter)->sort('Created', 'DESC'); |
||
| 78 | |||
| 79 | $gridFieldConfig = GridFieldConfig_RecordEditor::create() |
||
| 80 | ->addComponent(new GridFieldQueuedJobExecute('execute')) |
||
| 81 | ->addComponent(new GridFieldQueuedJobExecute('pause', function ($record) { |
||
| 82 | return $record->JobStatus == QueuedJob::STATUS_WAIT || $record->JobStatus == QueuedJob::STATUS_RUN; |
||
| 83 | })) |
||
| 84 | ->addComponent(new GridFieldQueuedJobExecute('resume', function ($record) { |
||
| 85 | return $record->JobStatus == QueuedJob::STATUS_PAUSED || $record->JobStatus == QueuedJob::STATUS_BROKEN; |
||
| 86 | })) |
||
| 87 | ->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton'); |
||
| 88 | |||
| 89 | |||
| 90 | // Set messages to HTML display format |
||
| 91 | $formatting = array( |
||
| 92 | 'Messages' => function ($val, $obj) { |
||
| 93 | return "<div style='max-width: 300px; max-height: 200px; overflow: auto;'>$obj->Messages</div>"; |
||
| 94 | }, |
||
| 95 | ); |
||
| 96 | $gridFieldConfig->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns') |
||
| 97 | ->setFieldFormatting($formatting); |
||
| 98 | |||
| 99 | // Replace gridfield |
||
| 100 | $grid = new GridField( |
||
| 101 | 'SilverStripe\\QueuedJobs\\DataObjects\\QueuedJobDescriptor', |
||
| 102 | _t('QueuedJobs.JobsFieldTitle', 'Jobs'), |
||
| 103 | $list, |
||
| 104 | $gridFieldConfig |
||
| 105 | ); |
||
| 106 | $grid->setForm($form); |
||
| 107 | $form->Fields()->replaceField('SilverStripe\\QueuedJobs\\DataObjects\\QueuedJobDescriptor', $grid); |
||
| 108 | |||
| 109 | if (Permission::check('ADMIN')) { |
||
| 110 | $types = ClassInfo::subclassesFor('SilverStripe\\QueuedJobs\\Services\\AbstractQueuedJob'); |
||
| 111 | $types = array_combine($types, $types); |
||
| 112 | unset($types['SilverStripe\\QueuedJobs\\Services\\AbstractQueuedJob']); |
||
| 113 | $jobType = DropdownField::create('JobType', _t('QueuedJobs.CREATE_JOB_TYPE', 'Create job of type'), $types); |
||
| 114 | $jobType->setEmptyString('(select job to create)'); |
||
| 115 | $form->Fields()->push($jobType); |
||
| 116 | |||
| 117 | $jobParams = TextareaField::create( |
||
| 118 | 'JobParams', |
||
| 119 | _t('QueuedJobs.JOB_TYPE_PARAMS', 'Constructor parameters for job creation (one per line)') |
||
| 120 | ); |
||
| 121 | $form->Fields()->push($jobParams); |
||
| 122 | |||
| 123 | $form->Fields()->push( |
||
| 124 | $dt = DatetimeField::create('JobStart', _t('QueuedJobs.START_JOB_TIME', 'Start job at')) |
||
| 125 | ); |
||
| 126 | $dt->getDateField()->setConfig('showcalendar', true); |
||
| 127 | |||
| 128 | $actions = $form->Actions(); |
||
| 129 | $actions->push(FormAction::create('createjob', _t('QueuedJobs.CREATE_NEW_JOB', 'Create new job'))); |
||
| 130 | } |
||
| 131 | |||
| 132 | $this->extend('updateEditForm', $form); |
||
| 133 | |||
| 134 | return $form; |
||
| 135 | } |
||
| 136 | |||
| 166 |