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