Conditions | 6 |
Paths | 6 |
Total Lines | 52 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
33 | public function getFormActions(TabulatorGrid_ItemRequest $itemRequest): FieldList |
||
34 | { |
||
35 | $actions = FieldList::create(); |
||
36 | $majorActions = CompositeField::create()->setName('MajorActions'); |
||
37 | $majorActions->setFieldHolderTemplate(get_class($majorActions) . '_holder_buttongroup'); |
||
38 | $actions->push($majorActions); |
||
39 | |||
40 | $record = $itemRequest->getRecord(); |
||
41 | |||
42 | if ($record->ID !== 0) { // existing record |
||
43 | if ($record->canEdit()) { |
||
44 | $majorActions->push( |
||
45 | FormAction::create('doSave', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Save', 'Save')) |
||
46 | ->setIcon('done') |
||
47 | ->addExtraClass('btn-outline-success') |
||
48 | ->setUseButtonTag(true) |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | if ($record->canDelete()) { |
||
53 | $actions->insertAfter( |
||
54 | 'MajorActions', |
||
55 | FormAction::create('doDelete', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Delete', 'Delete')) |
||
56 | ->setUseButtonTag(true) |
||
57 | ->setIcon('delete') |
||
58 | ->addExtraClass('btn-danger') |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | $actions->push($this->getRightGroupField($itemRequest)); |
||
63 | } else { // adding new record |
||
64 | //Change the Save label to 'Create' |
||
65 | $majorActions->push(FormAction::create('doSave', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Create', 'Create')) |
||
66 | ->setUseButtonTag(true) |
||
67 | ->setIcon('add') |
||
68 | ->addExtraClass('btn-success')); |
||
69 | |||
70 | // Add a Cancel link which is a button-like link and link back to one level up. |
||
71 | $crumbs = $itemRequest->Breadcrumbs(); |
||
72 | if ($crumbs && $crumbs->count() >= 2) { |
||
73 | $oneLevelUp = $crumbs->offsetGet($crumbs->count() - 2); |
||
74 | $text = sprintf( |
||
75 | "<a class=\"%s\" href=\"%s\">%s</a>", |
||
76 | "ms-auto btn btn-default", // CSS classes |
||
77 | $oneLevelUp->Link, // url |
||
78 | _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.CancelBtn', 'Cancel') // label |
||
79 | ); |
||
80 | $actions->insertAfter('MajorActions', new LiteralField('cancelbutton', $text)); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | return $actions; |
||
85 | } |
||
193 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.