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