| Conditions | 4 |
| Paths | 4 |
| Total Lines | 61 |
| 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 |
||
| 26 | public function sendPageDiff($subscriber_mail, $template, $id, $rev = null, $summary = '', $current_rev = null) |
||
| 27 | { |
||
| 28 | global $DIFF_INLINESTYLES; |
||
| 29 | |||
| 30 | // prepare replacements (keys not set in hrep will be taken from trep) |
||
| 31 | $trep = [ |
||
| 32 | 'PAGE' => $id, |
||
| 33 | 'NEWPAGE' => wl($id, $current_rev?('rev='.$current_rev):'', true, '&'), |
||
| 34 | 'SUMMARY' => $summary, |
||
| 35 | 'SUBSCRIBE' => wl($id, ['do' => 'subscribe'], true, '&'), |
||
| 36 | ]; |
||
| 37 | $hrep = []; |
||
| 38 | |||
| 39 | if ($rev) { |
||
|
|
|||
| 40 | $subject = 'changed'; |
||
| 41 | $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); |
||
| 42 | |||
| 43 | $old_content = rawWiki($id, $rev); |
||
| 44 | $new_content = rawWiki($id); |
||
| 45 | |||
| 46 | $df = new Diff( |
||
| 47 | explode("\n", $old_content), |
||
| 48 | explode("\n", $new_content) |
||
| 49 | ); |
||
| 50 | $dformat = new UnifiedDiffFormatter(); |
||
| 51 | $tdiff = $dformat->format($df); |
||
| 52 | |||
| 53 | $DIFF_INLINESTYLES = true; |
||
| 54 | $df = new Diff( |
||
| 55 | explode("\n", $old_content), |
||
| 56 | explode("\n", $new_content) |
||
| 57 | ); |
||
| 58 | $dformat = new InlineDiffFormatter(); |
||
| 59 | $hdiff = $dformat->format($df); |
||
| 60 | $hdiff = '<table>' . $hdiff . '</table>'; |
||
| 61 | $DIFF_INLINESTYLES = false; |
||
| 62 | } else { |
||
| 63 | $subject = 'newpage'; |
||
| 64 | $trep['OLDPAGE'] = '---'; |
||
| 65 | $tdiff = rawWiki($id); |
||
| 66 | $hdiff = nl2br(hsc($tdiff)); |
||
| 67 | } |
||
| 68 | |||
| 69 | $trep['DIFF'] = $tdiff; |
||
| 70 | $hrep['DIFF'] = $hdiff; |
||
| 71 | |||
| 72 | $headers = ['Message-Id' => $this->getMessageID($id)]; |
||
| 73 | if ($rev) { |
||
| 74 | $headers['In-Reply-To'] = $this->getMessageID($id, $rev); |
||
| 75 | } |
||
| 76 | |||
| 77 | return $this->send( |
||
| 78 | $subscriber_mail, |
||
| 79 | $subject, |
||
| 80 | $id, |
||
| 81 | $template, |
||
| 82 | $trep, |
||
| 83 | $hrep, |
||
| 84 | $headers |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | |||
| 89 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: