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