| Conditions | 24 |
| Paths | 13824 |
| Total Lines | 191 |
| 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 |
||
| 44 | public function show() |
||
| 45 | { |
||
| 46 | global $ID; |
||
| 47 | global $REV; |
||
| 48 | global $lang; |
||
| 49 | global $INPUT; |
||
| 50 | global $INFO; |
||
| 51 | $pagelog = new PageChangeLog($ID); |
||
| 52 | |||
| 53 | /* |
||
| 54 | * Determine diff type |
||
| 55 | */ |
||
| 56 | if ($this->DiffType === null) { |
||
|
|
|||
| 57 | $this->diffType = $INPUT->str('difftype'); |
||
| 58 | if (empty($this->difftype)) { |
||
| 59 | $this->diffType = get_doku_pref('difftype', $this->diffType); |
||
| 60 | if (empty($this->diffType) && $INFO['ismobile']) { |
||
| 61 | $this->diffType = 'inline'; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | if ($this->dffType != 'inline') $this->dffType = 'sidebyside'; |
||
| 66 | |||
| 67 | /* |
||
| 68 | * Determine requested revision(s) |
||
| 69 | */ |
||
| 70 | // we're trying to be clever here, revisions to compare can be either |
||
| 71 | // given as rev and rev2 parameters, with rev2 being optional. Or in an |
||
| 72 | // array in rev2. |
||
| 73 | $rev1 = $REV; |
||
| 74 | |||
| 75 | $rev2 = $INPUT->ref('rev2'); |
||
| 76 | if (is_array($rev2)) { |
||
| 77 | $rev1 = (int) $rev2[0]; |
||
| 78 | $rev2 = (int) $rev2[1]; |
||
| 79 | |||
| 80 | if (!$rev1) { |
||
| 81 | $rev1 = $rev2; |
||
| 82 | unset($rev2); |
||
| 83 | } |
||
| 84 | } else { |
||
| 85 | $rev2 = $INPUT->int('rev2'); |
||
| 86 | } |
||
| 87 | |||
| 88 | /* |
||
| 89 | * Determine left and right revision, its texts and the header |
||
| 90 | */ |
||
| 91 | $r_minor = ''; |
||
| 92 | $l_minor = ''; |
||
| 93 | |||
| 94 | if ($this->text) { // compare text to the most current revision |
||
| 95 | $l_rev = ''; |
||
| 96 | $l_text = rawWiki($ID, ''); |
||
| 97 | $l_head = '<a class="wikilink1" href="'. wl($ID) .'">' |
||
| 98 | . $ID .' '. dformat((int) @filemtime(wikiFN($ID))) .'</a> ' |
||
| 99 | . $lang['current']; |
||
| 100 | |||
| 101 | $r_rev = ''; |
||
| 102 | $r_text = cleanText($this->text); |
||
| 103 | $r_head = $lang['yours']; |
||
| 104 | } else { |
||
| 105 | if ($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted |
||
| 106 | // make sure order is correct (older on the left) |
||
| 107 | if ($rev1 < $rev2) { |
||
| 108 | $l_rev = $rev1; |
||
| 109 | $r_rev = $rev2; |
||
| 110 | } else { |
||
| 111 | $l_rev = $rev2; |
||
| 112 | $r_rev = $rev1; |
||
| 113 | } |
||
| 114 | } elseif ($rev1) { // single revision given, compare to current |
||
| 115 | $r_rev = ''; |
||
| 116 | $l_rev = $rev1; |
||
| 117 | } else { // no revision was given, compare previous to current |
||
| 118 | $r_rev = ''; |
||
| 119 | $revs = $pagelog->getRevisions(0, 1); |
||
| 120 | $l_rev = $revs[0]; |
||
| 121 | $REV = $l_rev; // store revision back in $REV |
||
| 122 | } |
||
| 123 | |||
| 124 | // when both revisions are empty then the page was created just now |
||
| 125 | if (!$l_rev && !$r_rev) { |
||
| 126 | $l_text = ''; |
||
| 127 | } else { |
||
| 128 | $l_text = rawWiki($ID, $l_rev); |
||
| 129 | } |
||
| 130 | $r_text = rawWiki($ID, $r_rev); |
||
| 131 | |||
| 132 | list($l_head, $r_head, $l_minor, $r_minor) = $this->diffHead( |
||
| 133 | $l_rev, $r_rev, null, false, ($this->diffType == 'inline') |
||
| 134 | ); |
||
| 135 | } |
||
| 136 | |||
| 137 | /* |
||
| 138 | * Build navigation |
||
| 139 | */ |
||
| 140 | $l_nav = ''; |
||
| 141 | $r_nav = ''; |
||
| 142 | if (!$this->text) { |
||
| 143 | list($l_nav, $r_nav) = $this->diffNavigation($pagelog, $this->diffType, $l_rev, $r_rev); |
||
| 144 | } |
||
| 145 | /* |
||
| 146 | * Create diff object and the formatter |
||
| 147 | */ |
||
| 148 | $diff = new \Diff(explode("\n", $l_text), explode("\n", $r_text)); |
||
| 149 | |||
| 150 | if ($this->diffType == 'inline') { |
||
| 151 | $diffformatter = new \InlineDiffFormatter(); |
||
| 152 | } else { |
||
| 153 | $diffformatter = new \TableDiffFormatter(); |
||
| 154 | } |
||
| 155 | /* |
||
| 156 | * Display intro |
||
| 157 | */ |
||
| 158 | if ($this->showIntro) print p_locale_xhtml('diff'); |
||
| 159 | |||
| 160 | /* |
||
| 161 | * Display type and exact reference |
||
| 162 | */ |
||
| 163 | if (!$this->text) { |
||
| 164 | print '<div class="diffoptions group">'; |
||
| 165 | |||
| 166 | // create the form to select diff view type |
||
| 167 | $form = new Form(['action' => wl()]); |
||
| 168 | $form->setHiddenField('id', $ID); |
||
| 169 | $form->setHiddenField('rev2[0]', $l_rev); |
||
| 170 | $form->setHiddenField('rev2[1]', $r_rev); |
||
| 171 | $form->setHiddenField('do', 'diff'); |
||
| 172 | $options = array( |
||
| 173 | 'sidebyside' => $lang['diff_side'], |
||
| 174 | 'inline' => $lang['diff_inline'] |
||
| 175 | ); |
||
| 176 | $input = $form->addDropdown('difftype', $options, $lang['diff_type']) |
||
| 177 | ->val($this->diffType)->addClass('quickselect'); |
||
| 178 | $input->useInput(false); // inhibit prefillInput() during toHTML() process |
||
| 179 | $form->addButton('do[diff]', 'Go')->attr('type','submit'); |
||
| 180 | print $form->toHTML(); |
||
| 181 | |||
| 182 | print '<p>'; |
||
| 183 | // link to exactly this view FS#2835 |
||
| 184 | print $this->diffViewlink($this->diffType, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']); |
||
| 185 | print '</p>'; |
||
| 186 | |||
| 187 | print '</div>'; // .diffoptions |
||
| 188 | } |
||
| 189 | |||
| 190 | /* |
||
| 191 | * Display diff view table |
||
| 192 | */ |
||
| 193 | print '<div class="table">'; |
||
| 194 | print '<table class="diff diff_'. $this->diffType .'">'; |
||
| 195 | |||
| 196 | //navigation and header |
||
| 197 | if ($this->diffType == 'inline') { |
||
| 198 | if (!$this->text) { |
||
| 199 | print '<tr>' |
||
| 200 | . '<td class="diff-lineheader">-</td>' |
||
| 201 | . '<td class="diffnav">'. $l_nav .'</td>' |
||
| 202 | . '</tr>'; |
||
| 203 | print '<tr>' |
||
| 204 | . '<th class="diff-lineheader">-</th>' |
||
| 205 | . '<th '. $l_minor .'>'. $l_head .'</th>' |
||
| 206 | .'</tr>'; |
||
| 207 | } |
||
| 208 | print '<tr>' |
||
| 209 | . '<td class="diff-lineheader">+</td>' |
||
| 210 | . '<td class="diffnav">'. $r_nav .'</td>' |
||
| 211 | .'</tr>'; |
||
| 212 | print '<tr>' |
||
| 213 | . '<th class="diff-lineheader">+</th>' |
||
| 214 | . '<th '. $r_minor .'>'. $r_head .'</th>' |
||
| 215 | . '</tr>'; |
||
| 216 | } else { |
||
| 217 | if (!$this->text) { |
||
| 218 | print '<tr>' |
||
| 219 | . '<td colspan="2" class="diffnav">'. $l_nav .'</td>' |
||
| 220 | . '<td colspan="2" class="diffnav">'. $r_nav .'</td>' |
||
| 221 | . '</tr>'; |
||
| 222 | } |
||
| 223 | print '<tr>' |
||
| 224 | . '<th colspan="2" '. $l_minor .'>'. $l_head .'</th>' |
||
| 225 | . '<th colspan="2" '. $r_minor .'>'. $r_head .'</th>' |
||
| 226 | . '</tr>'; |
||
| 227 | } |
||
| 228 | |||
| 229 | //diff view |
||
| 230 | print html_insert_softbreaks($diffformatter->format($diff)); |
||
| 231 | |||
| 232 | print '</table>'; |
||
| 233 | print '</div>'. DOKU_LF; |
||
| 234 | } |
||
| 235 | |||
| 478 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.