Conditions | 8 |
Paths | 13 |
Total Lines | 62 |
Code Lines | 36 |
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 |
||
10 | protected function getFormActions() { |
||
11 | $actions = parent::getFormActions(); |
||
12 | |||
13 | // Check if record is versionable |
||
14 | $record = $this->getRecord(); |
||
15 | if(!$record || !$record->has_extension('Versioned')) { |
||
16 | return $actions; |
||
17 | } |
||
18 | |||
19 | // Save & Publish action |
||
20 | if($record->canPublish()) { |
||
21 | // "publish", as with "save", it supports an alternate state to show when action is needed. |
||
22 | $publish = FormAction::create( |
||
23 | 'doPublish', |
||
24 | _t('VersionedGridFieldItemRequest.BUTTONPUBLISH', 'Publish') |
||
25 | ) |
||
26 | ->setUseButtonTag(true) |
||
27 | ->addExtraClass('ss-ui-action-constructive') |
||
28 | ->setAttribute('data-icon', 'accept'); |
||
29 | |||
30 | // Insert after save |
||
31 | if($actions->fieldByName('action_doSave')) { |
||
32 | $actions->insertAfter('action_doSave', $publish); |
||
33 | } else { |
||
34 | $actions->push($publish); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | // Unpublish action |
||
39 | $isPublished = $record->isPublished(); |
||
40 | if($isPublished && $record->canUnpublish()) { |
||
41 | $actions->push( |
||
42 | FormAction::create( |
||
43 | 'doUnpublish', |
||
44 | _t('VersionedGridFieldItemRequest.BUTTONUNPUBLISH', 'Unpublish') |
||
45 | ) |
||
46 | ->setUseButtonTag(true) |
||
47 | ->setDescription(_t( |
||
48 | 'VersionedGridFieldItemRequest.BUTTONUNPUBLISHDESC', |
||
49 | 'Remove this record from the published site' |
||
50 | )) |
||
51 | ->addExtraClass('ss-ui-action-destructive') |
||
52 | ); |
||
53 | } |
||
54 | |||
55 | // Archive action |
||
56 | if($record->canArchive()) { |
||
57 | // Replace "delete" action |
||
58 | $actions->removeByName('action_doDelete'); |
||
59 | |||
60 | // "archive" |
||
61 | $actions->push( |
||
62 | FormAction::create('doArchive', _t('VersionedGridFieldItemRequest.ARCHIVE','Archive')) |
||
63 | ->setDescription(_t( |
||
64 | 'VersionedGridFieldItemRequest.BUTTONARCHIVEDESC', |
||
65 | 'Unpublish and send to archive' |
||
66 | )) |
||
67 | ->addExtraClass('delete ss-ui-action-destructive') |
||
68 | ); |
||
69 | } |
||
70 | return $actions; |
||
71 | } |
||
72 | |||
197 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.