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