| Conditions | 10 |
| Paths | 84 |
| Total Lines | 53 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 73 | public function prepare_context($use_quick_reply, &$editorOptions, $board) |
||
| 74 | { |
||
| 75 | global $context, $options, $txt; |
||
| 76 | |||
| 77 | // Check if the draft functions are enabled and that they have permission to use them (for quick topic.) |
||
| 78 | $context['drafts_save'] = $use_quick_reply && allowedTo('post_draft') && $context['can_post_new']; |
||
| 79 | $context['drafts_autosave'] = $context['drafts_save'] && self::$_autosave_enabled && allowedTo('post_autosave_draft') && !empty($options['drafts_autosave_enabled']); |
||
| 80 | |||
| 81 | // Enable the drafts functions for the QR area |
||
| 82 | if (!empty($context['drafts_save'])) |
||
| 83 | { |
||
| 84 | Txt::load('Drafts'); |
||
| 85 | |||
| 86 | if ($context['drafts_autosave']) |
||
| 87 | { |
||
| 88 | Txt::load('Post'); |
||
| 89 | |||
| 90 | $editorOptions['plugin_addons'] = $editorOptions['plugin_addons'] ?? []; |
||
| 91 | $editorOptions['plugin_options'] = $editorOptions['plugin_options'] ?? []; |
||
| 92 | |||
| 93 | // @todo remove |
||
| 94 | $context['drafts_autosave_frequency'] = self::$_autosave_frequency; |
||
| 95 | |||
| 96 | $editorOptions['plugin_addons'][] = 'draft'; |
||
| 97 | $editorOptions['plugin_options'][] = ' |
||
| 98 | draftOptions: { |
||
| 99 | sLastNote: \'draft_lastautosave\', |
||
| 100 | sSceditorID: \'' . $editorOptions['id'] . '\', |
||
| 101 | sType: \'post\', |
||
| 102 | iBoard: ' . $board . ', |
||
| 103 | iFreq: ' . self::$_autosave_frequency . ', |
||
| 104 | sLastID: \'id_draft\', |
||
| 105 | sTextareaID: \'' . $editorOptions['id'] . '\', |
||
| 106 | id_draft: ' . (empty($context['id_draft']) ? 0 : $context['id_draft']) . ' |
||
| 107 | }'; |
||
| 108 | |||
| 109 | loadJavascriptFile('editor/drafts.plugin.js', ['defer' => true]); |
||
| 110 | } |
||
| 111 | |||
| 112 | // Hide this for quick topic |
||
| 113 | $context['shortcuts_text'] = ''; |
||
| 114 | |||
| 115 | $editorOptions['buttons'] = $editorOptions['buttons'] ?? []; |
||
| 116 | array_unshift($editorOptions['buttons'], [ |
||
| 117 | 'name' => 'save_draft', |
||
| 118 | 'value' => $txt['draft_save'], |
||
| 119 | 'options' => 'onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d"', |
||
| 120 | ]); |
||
| 121 | |||
| 122 | $editorOptions['hidden_fields'] = $editorOptions['hidden_fields'] ?? []; |
||
| 123 | $editorOptions['hidden_fields'][] = [ |
||
| 124 | 'name' => 'id_draft', |
||
| 125 | 'value' => empty($context['id_draft']) ? 0 : $context['id_draft'], |
||
| 126 | ]; |
||
| 130 |