| Conditions | 22 |
| Paths | > 20000 |
| Total Lines | 152 |
| 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 |
||
| 24 | public function show() |
||
| 25 | { |
||
| 26 | global $INPUT; |
||
| 27 | global $ID; |
||
| 28 | global $REV; |
||
| 29 | global $DATE; |
||
| 30 | global $PRE; |
||
| 31 | global $SUF; |
||
| 32 | global $INFO; |
||
| 33 | global $SUM; |
||
| 34 | global $lang; |
||
| 35 | global $conf; |
||
| 36 | global $TEXT; |
||
| 37 | |||
| 38 | global $license; |
||
| 39 | |||
| 40 | if ($INPUT->has('changecheck')) { |
||
| 41 | $check = $INPUT->str('changecheck'); |
||
| 42 | } elseif (!$INFO['exists']) { |
||
| 43 | // $TEXT has been loaded from page template |
||
| 44 | $check = md5(''); |
||
| 45 | } else { |
||
| 46 | $check = md5($TEXT); |
||
| 47 | } |
||
| 48 | $mod = (md5($TEXT) !== $check); |
||
| 49 | |||
| 50 | $wr = $INFO['writable'] && !$INFO['locked']; |
||
| 51 | |||
| 52 | // intro locale text (edit, rditrev, or read) |
||
| 53 | if ($wr) { |
||
| 54 | $intro = ($REV) ? 'editrev' : 'edit'; |
||
| 55 | } else { |
||
| 56 | // check pseudo action 'source' |
||
| 57 | if (!actionOK('source')) { |
||
| 58 | msg('Command disabled: source', -1); |
||
| 59 | return; |
||
| 60 | } |
||
| 61 | $intro = 'read'; |
||
| 62 | } |
||
| 63 | |||
| 64 | // create the Editor form |
||
| 65 | $form = new Form(['id' => 'dw__editform']); |
||
| 66 | $form->setHiddenField('id', $ID); |
||
| 67 | $form->setHiddenField('rev', $REV); |
||
| 68 | $form->setHiddenField('date', $DATE); |
||
| 69 | $form->setHiddenField('prefix', $PRE .'.'); |
||
| 70 | $form->setHiddenField('suffix', $SUF); |
||
| 71 | $form->setHiddenField('changecheck', $check); |
||
| 72 | |||
| 73 | // prepare data for EDIT_FORM_ALTERNATE event |
||
| 74 | $data = array( |
||
| 75 | 'form' => $form, |
||
| 76 | 'wr' => $wr, |
||
| 77 | 'media_manager' => true, |
||
| 78 | 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section', |
||
| 79 | 'intro_locale' => $intro, |
||
| 80 | ); |
||
| 81 | |||
| 82 | $this->addToolbar($data, $wr); |
||
| 83 | |||
| 84 | if ($data['target'] !== 'section') { |
||
| 85 | // Only emit event if page is writable, section edit data is valid and |
||
| 86 | // edit target is not section. |
||
| 87 | Event::createAndTrigger('EDIT_FORM_ADDTEXTAREA', $data, [$this,'addTextarea'], true); |
||
| 88 | } else { |
||
| 89 | $this->addTextarea($data); |
||
| 90 | } |
||
| 91 | |||
| 92 | $form->setHiddenField('target', $data['target']); |
||
| 93 | |||
| 94 | if ($INPUT->has('hid')) { |
||
| 95 | $form->setHiddenField('hid', $INPUT->str('hid')); |
||
| 96 | } |
||
| 97 | if ($INPUT->has('codeblockOffset')) { |
||
| 98 | $form->setHiddenField('codeblockOffset', $INPUT->str('codeblockOffset')); |
||
| 99 | } |
||
| 100 | |||
| 101 | $form->addTagOpen('div')->id('wiki__editbar')->addClass('editBar'); |
||
| 102 | |||
| 103 | $form->addTagOpen('div')->id('size__ctl'); |
||
| 104 | $form->addTagClose('div'); |
||
| 105 | |||
| 106 | if ($wr) { |
||
| 107 | // add edit buttons: save, preview, cancel |
||
| 108 | $form->addTagOpen('div')->addClass('editButtons'); |
||
| 109 | $form->addButton('do[save]', $lang['btn_save'])->attr('type', 'submit') |
||
| 110 | ->attrs(['accesskey' => 's', 'tabindex' => '4']) |
||
| 111 | ->id('edbtn__save'); |
||
| 112 | $form->addButton('do[preview]', $lang['btn_preview'])->attr('type', 'submit') |
||
| 113 | ->attrs(['accesskey' => 'p', 'tabindex' => '5']) |
||
| 114 | ->id('edbtn__preview'); |
||
| 115 | $form->addButton('do[cancel]', $lang['btn_cancel'])->attr('type', 'submit') |
||
| 116 | ->attrs(['tabindex' => '6']); |
||
| 117 | $form->addTagClose('div'); // close div editButtons class |
||
| 118 | |||
| 119 | // add a textbox for edit summary |
||
| 120 | $form->addTagOpen('div')->addClass('summary'); |
||
| 121 | $input = $form->addTextInput('summary', $lang['summary']) |
||
| 122 | ->attrs(['size' => '50', 'tabindex' => '2']) |
||
| 123 | ->id('edit__summary')->addClass('edit') |
||
| 124 | ->val($SUM); |
||
| 125 | $input->getLabel()->attr('class', 'nowrap'); |
||
| 126 | |||
| 127 | // adds a checkbox for minor edits for logged in users |
||
| 128 | if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { |
||
| 129 | $form->addHTML(' '); |
||
| 130 | $form->addCheckbox('minor', $lang['minoredit'])->id('edit__minoredit')->addClass('nowrap')->val('1'); |
||
| 131 | } |
||
| 132 | $form->addTagClose('div'); // close div summary class |
||
| 133 | } |
||
| 134 | |||
| 135 | $form->addTagClose('div'); // close div editBar class |
||
| 136 | |||
| 137 | // license note |
||
| 138 | if ($wr && $conf['license']) { |
||
| 139 | $attr = array( |
||
| 140 | 'href' => $license[$conf['license']]['url'], |
||
| 141 | 'rel' => 'license', |
||
| 142 | 'class' => 'urlextern', |
||
| 143 | 'target' => $conf['target']['extern'] ? $conf['target']['extern'] : '', |
||
| 144 | ); |
||
| 145 | $form->addTagOpen('div')->addClass('license'); |
||
| 146 | $form->addHTML($lang['licenseok'] |
||
| 147 | .' <a '.buildAttributes($attr, true).'>'.$license[$conf['license']]['name'].'</a>' |
||
| 148 | ); |
||
| 149 | $form->addTagClose('div'); |
||
| 150 | } |
||
| 151 | |||
| 152 | // start editor html output |
||
| 153 | if ($wr) { |
||
| 154 | // sets changed to true when previewed |
||
| 155 | echo '<script>/*<![CDATA[*/'.'textChanged = '. ($mod ? 'true' : 'false') .'/*!]]>*/</script>'; |
||
| 156 | } |
||
| 157 | |||
| 158 | // print intro locale text (edit, rditrev, or read.txt) |
||
| 159 | if (isset($data['intro_locale'])) { |
||
| 160 | echo p_locale_xhtml($data['intro_locale']); |
||
| 161 | } |
||
| 162 | |||
| 163 | echo '<div class="editBox" role="application">'; |
||
| 164 | |||
| 165 | echo '<div id="draft__status" class="draft__status">'; |
||
| 166 | $draft = new \dokuwiki\Draft($ID, $INFO['client']); |
||
| 167 | if ($draft->isDraftAvailable()) { |
||
| 168 | echo $draft->getDraftMessage(); |
||
| 169 | } |
||
| 170 | echo '</div>'; |
||
| 171 | |||
| 172 | echo $form->toHTML('Edit'); |
||
| 173 | |||
| 174 | echo '</div>'; // close div editBox class |
||
| 175 | } |
||
| 176 | |||
| 228 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.