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