| Conditions | 12 |
| Paths | 48 |
| Total Lines | 131 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 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 |
||
| 169 | public function getCMSFields() { |
||
| 170 | |||
| 171 | $cmsUsers = Member::mapInCMSGroups(); |
||
| 172 | |||
| 173 | $fields = new FieldList(new TabSet('Root')); |
||
| 174 | |||
| 175 | $fields->addFieldToTab('Root.Main', new TextField('Title', $this->fieldLabel('Title'))); |
||
| 176 | $fields->addFieldToTab('Root.Main', new TextareaField('Description', $this->fieldLabel('Description'))); |
||
| 177 | $fields->addFieldToTab('Root.Main', TextField::create( |
||
| 178 | 'InitialActionButtonText', |
||
| 179 | _t('WorkflowDefinition.INITIAL_ACTION_BUTTON_TEXT', 'Initial Action Button Text') |
||
| 180 | )); |
||
| 181 | if($this->ID) { |
||
| 182 | $fields->addFieldToTab('Root.Main', new CheckboxSetField('Users', _t('WorkflowDefinition.USERS', 'Users'), $cmsUsers)); |
||
| 183 | $fields->addFieldToTab('Root.Main', new TreeMultiselectField('Groups', _t('WorkflowDefinition.GROUPS', 'Groups'), 'Group')); |
||
| 184 | } |
||
| 185 | |||
| 186 | if (class_exists('AbstractQueuedJob')) { |
||
| 187 | $before = _t('WorkflowDefinition.SENDREMINDERDAYSBEFORE', 'Send reminder email after '); |
||
| 188 | $after = _t('WorkflowDefinition.SENDREMINDERDAYSAFTER', ' days without action.'); |
||
| 189 | |||
| 190 | $fields->addFieldToTab('Root.Main', new FieldGroup( |
||
| 191 | _t('WorkflowDefinition.REMINDEREMAIL', 'Reminder Email'), |
||
| 192 | new LabelField('ReminderEmailBefore', $before), |
||
| 193 | new NumericField('RemindDays', ''), |
||
| 194 | new LabelField('ReminderEmailAfter', $after) |
||
| 195 | )); |
||
| 196 | } |
||
| 197 | |||
| 198 | if($this->ID) { |
||
| 199 | if ($this->Template) { |
||
| 200 | $template = $this->workflowService->getNamedTemplate($this->Template); |
||
| 201 | $fields->addFieldToTab('Root.Main', new ReadonlyField('Template', $this->fieldLabel('Template'), $this->Template)); |
||
| 202 | $fields->addFieldToTab('Root.Main', new ReadonlyField('TemplateDesc', _t('WorkflowDefinition.TEMPLATE_INFO', 'Template Info'), $template ? $template->getDescription() : '')); |
||
| 203 | $fields->addFieldToTab('Root.Main', $tv = new ReadonlyField('TemplateVersion', $this->fieldLabel('TemplateVersion'))); |
||
| 204 | $tv->setRightTitle(sprintf(_t('WorkflowDefinition.LATEST_VERSION', 'Latest version is %s'), $template ? $template->getVersion() : '')); |
||
| 205 | |||
| 206 | } |
||
| 207 | |||
| 208 | $fields->addFieldToTab('Root.Main', new WorkflowField( |
||
| 209 | 'Workflow', _t('WorkflowDefinition.WORKFLOW', 'Workflow'), $this |
||
| 210 | )); |
||
| 211 | } else { |
||
| 212 | // add in the 'template' info |
||
| 213 | $templates = $this->workflowService->getTemplates(); |
||
| 214 | |||
| 215 | if (is_array($templates)) { |
||
| 216 | $items = array('' => ''); |
||
| 217 | foreach ($templates as $template) { |
||
| 218 | $items[$template->getName()] = $template->getName(); |
||
| 219 | } |
||
| 220 | $templates = array_combine(array_keys($templates), array_keys($templates)); |
||
| 221 | |||
| 222 | $fields->addFieldToTab('Root.Main', $dd = new DropdownField('Template', _t('WorkflowDefinition.CHOOSE_TEMPLATE', 'Choose template (optional)'), $items)); |
||
| 223 | $dd->setRightTitle(_t('WorkflowDefinition.CHOOSE_TEMPLATE_RIGHT', 'If set, this workflow definition will be automatically updated if the template is changed')); |
||
| 224 | } |
||
| 225 | |||
| 226 | /* |
||
| 227 | * Uncomment to allow pre-uploaded exports to appear in a new DropdownField. |
||
| 228 | * |
||
| 229 | * $import = singleton('WorkflowDefinitionImporter')->getImportedWorkflows(); |
||
| 230 | * if (is_array($import)) { |
||
| 231 | * $_imports = array('' => ''); |
||
| 232 | * foreach ($imports as $import) { |
||
| 233 | * $_imports[$import->getName()] = $import->getName(); |
||
| 234 | * } |
||
| 235 | * $imports = array_combine(array_keys($_imports), array_keys($_imports)); |
||
| 236 | * $fields->addFieldToTab('Root.Main', new DropdownField('Import', _t('WorkflowDefinition.CHOOSE_IMPORT', 'Choose import (optional)'), $imports)); |
||
| 237 | * } |
||
| 238 | */ |
||
| 239 | |||
| 240 | $message = _t( |
||
| 241 | 'WorkflowDefinition.ADDAFTERSAVING', |
||
| 242 | 'You can add workflow steps after you save for the first time.' |
||
| 243 | ); |
||
| 244 | $fields->addFieldToTab('Root.Main', new LiteralField( |
||
| 245 | 'AddAfterSaving', "<p class='message notice'>$message</p>" |
||
| 246 | )); |
||
| 247 | } |
||
| 248 | |||
| 249 | if($this->ID && Permission::check('VIEW_ACTIVE_WORKFLOWS')) { |
||
| 250 | $active = $this->Instances()->filter(array( |
||
| 251 | 'WorkflowStatus' => array('Active', 'Paused') |
||
| 252 | )); |
||
| 253 | |||
| 254 | $active = new GridField( |
||
| 255 | 'Active', |
||
| 256 | _t('WorkflowDefinition.WORKFLOWACTIVEIINSTANCES', 'Active Workflow Instances'), |
||
| 257 | $active, |
||
| 258 | new GridFieldConfig_RecordEditor()); |
||
| 259 | |||
| 260 | $active->getConfig()->removeComponentsByType('GridFieldAddNewButton'); |
||
| 261 | $active->getConfig()->removeComponentsByType('GridFieldDeleteAction'); |
||
| 262 | |||
| 263 | if(!Permission::check('REASSIGN_ACTIVE_WORKFLOWS')) { |
||
| 264 | $active->getConfig()->removeComponentsByType('GridFieldEditButton'); |
||
| 265 | $active->getConfig()->addComponent(new GridFieldViewButton()); |
||
| 266 | $active->getConfig()->addComponent(new GridFieldDetailForm()); |
||
| 267 | } |
||
| 268 | |||
| 269 | $completed = $this->Instances()->filter(array( |
||
| 270 | 'WorkflowStatus' => array('Complete', 'Cancelled') |
||
| 271 | )); |
||
| 272 | |||
| 273 | $config = new GridFieldConfig_Base(); |
||
| 274 | $config->addComponent(new GridFieldEditButton()); |
||
| 275 | $config->addComponent(new GridFieldDetailForm()); |
||
| 276 | |||
| 277 | $completed = new GridField( |
||
| 278 | 'Completed', |
||
| 279 | _t('WorkflowDefinition.WORKFLOWCOMPLETEDIINSTANCES', 'Completed Workflow Instances'), |
||
| 280 | $completed, |
||
| 281 | $config); |
||
| 282 | |||
| 283 | $fields->findOrMakeTab( |
||
| 284 | 'Root.Active', |
||
| 285 | _t('WorkflowEmbargoExpiryExtension.ActiveWorkflowStateTitle', 'Active') |
||
| 286 | ); |
||
| 287 | $fields->addFieldToTab('Root.Active', $active); |
||
| 288 | |||
| 289 | $fields->findOrMakeTab( |
||
| 290 | 'Root.Completed', |
||
| 291 | _t('WorkflowEmbargoExpiryExtension.CompletedWorkflowStateTitle', 'Completed') |
||
| 292 | ); |
||
| 293 | $fields->addFieldToTab('Root.Completed', $completed); |
||
| 294 | } |
||
| 295 | |||
| 296 | $this->extend('updateCMSFields', $fields); |
||
| 297 | |||
| 298 | return $fields; |
||
| 299 | } |
||
| 300 | |||
| 454 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.