| Conditions | 4 |
| Paths | 2 |
| Total Lines | 70 |
| Code Lines | 43 |
| 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 |
||
| 90 | public function getEditForm($id = null, $fields = null) |
||
| 91 | { |
||
| 92 | $form = parent::getEditForm($id, $fields); |
||
| 93 | |||
| 94 | $filter = $this->jobQueue->getJobListFilter(null, self::config()->max_finished_jobs_age); |
||
| 95 | |||
| 96 | $list = DataList::create(QueuedJobDescriptor::class); |
||
| 97 | $list = $list->where($filter)->sort('Created', 'DESC'); |
||
| 98 | |||
| 99 | $gridFieldConfig = GridFieldConfig_RecordEditor::create() |
||
| 100 | ->addComponent(new GridFieldQueuedJobExecute('execute')) |
||
| 101 | ->addComponent(new GridFieldQueuedJobExecute('pause', function ($record) { |
||
| 102 | return $record->JobStatus == QueuedJob::STATUS_WAIT || $record->JobStatus == QueuedJob::STATUS_RUN; |
||
| 103 | })) |
||
| 104 | ->addComponent(new GridFieldQueuedJobExecute('resume', function ($record) { |
||
| 105 | return $record->JobStatus == QueuedJob::STATUS_PAUSED || $record->JobStatus == QueuedJob::STATUS_BROKEN; |
||
| 106 | })) |
||
| 107 | ->removeComponentsByType(GridFieldAddNewButton::class); |
||
| 108 | |||
| 109 | |||
| 110 | // Set messages to HTML display format |
||
| 111 | $formatting = array( |
||
| 112 | 'Messages' => function ($val, $obj) { |
||
| 113 | return "<div style='max-width: 300px; max-height: 200px; overflow: auto;'>$obj->Messages</div>"; |
||
| 114 | }, |
||
| 115 | ); |
||
| 116 | $gridFieldConfig->getComponentByType(GridFieldDataColumns::class) |
||
| 117 | ->setFieldFormatting($formatting); |
||
| 118 | |||
| 119 | // Replace gridfield |
||
| 120 | /** @skipUpgrade */ |
||
| 121 | $grid = GridField::create( |
||
| 122 | QueuedJobDescriptor::class, |
||
| 123 | _t(__CLASS__ . '.JobsFieldTitle', 'Jobs'), |
||
| 124 | $list, |
||
| 125 | $gridFieldConfig |
||
| 126 | ); |
||
| 127 | $grid->setForm($form); |
||
| 128 | /** @skipUpgrade */ |
||
| 129 | $form->Fields()->replaceField('QueuedJobDescriptor', $grid); |
||
| 130 | |||
| 131 | if (Permission::check('ADMIN')) { |
||
| 132 | $types = ClassInfo::subclassesFor(AbstractQueuedJob::class); |
||
| 133 | $types = array_combine($types, $types); |
||
| 134 | unset($types[AbstractQueuedJob::class]); |
||
| 135 | $jobType = DropdownField::create('JobType', _t(__CLASS__ . '.CREATE_JOB_TYPE', 'Create job of type'), $types); |
||
| 136 | $jobType->setEmptyString('(select job to create)'); |
||
| 137 | $form->Fields()->push($jobType); |
||
| 138 | |||
| 139 | $jobParams = TextareaField::create( |
||
| 140 | 'JobParams', |
||
| 141 | _t(__CLASS__ . '.JOB_TYPE_PARAMS', 'Constructor parameters for job creation (one per line)') |
||
| 142 | ); |
||
| 143 | $form->Fields()->push($jobParams); |
||
| 144 | |||
| 145 | $form->Fields()->push( |
||
| 146 | $dt = DatetimeField::create('JobStart', _t(__CLASS__ . '.START_JOB_TIME', 'Start job at')) |
||
| 147 | ); |
||
| 148 | |||
| 149 | $actions = $form->Actions(); |
||
| 150 | $actions->push( |
||
| 151 | FormAction::create('createjob', _t(__CLASS__ . '.CREATE_NEW_JOB', 'Create new job')) |
||
| 152 | ->addExtraClass('btn btn-primary') |
||
| 153 | ); |
||
| 154 | } |
||
| 155 | |||
| 156 | $this->extend('updateEditForm', $form); |
||
| 157 | |||
| 158 | return $form; |
||
| 159 | } |
||
| 160 | |||
| 198 |