| Conditions | 9 |
| Paths | 44 |
| Total Lines | 71 |
| Code Lines | 37 |
| 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 |
||
| 70 | public function getDiffList($highestVersion = null, $limit = 100) { |
||
| 71 | // This can leak secured content if it was protected via inherited setting. |
||
| 72 | // For now the users will need to be aware about this shortcoming. |
||
| 73 | $offset = $highestVersion ? "AND \"SiteTree_versions\".\"Version\"<='".(int)$highestVersion."'" : ''; |
||
| 74 | // Get just enough elements for diffing. We need one more than desired to have something to compare to. |
||
| 75 | $qLimit = (int)$limit + 1; |
||
| 76 | $versions = $this->owner->allVersions( |
||
| 77 | "\"WasPublished\"='1' AND \"CanViewType\" IN ('Anyone', 'Inherit') $offset", |
||
| 78 | "\"SiteTree\".\"LastEdited\" DESC, \"SiteTree\".\"ID\" DESC", |
||
| 79 | $qLimit |
||
| 80 | ); |
||
| 81 | |||
| 82 | // Process the list to add the comparisons. |
||
| 83 | $changeList = new ArrayList(); |
||
| 84 | $previous = null; |
||
| 85 | $count = 0; |
||
| 86 | foreach ($versions as $version) { |
||
| 87 | $changed = false; |
||
| 88 | |||
| 89 | // Check if we have something to compare with. |
||
| 90 | if (isset($previous)) { |
||
| 91 | |||
| 92 | // Produce the diff fields for use in the template. |
||
| 93 | if ($version->Title != $previous->Title) { |
||
| 94 | $diffTitle = Diff::compareHTML($version->Title, $previous->Title); |
||
| 95 | |||
| 96 | $version->DiffTitle = DBField::create_field('HTMLText', null); |
||
| 97 | $version->DiffTitle->setValue( |
||
| 98 | sprintf( |
||
| 99 | '<div><em>%s</em> ' . $diffTitle . '</div>', |
||
| 100 | _t('RSSHistory.TITLECHANGED', 'Title has changed:') |
||
| 101 | ) |
||
| 102 | ); |
||
| 103 | $changed = true; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($version->Content != $previous->Content) { |
||
| 107 | $diffContent = Diff::compareHTML($version->Content, $previous->Content); |
||
| 108 | |||
| 109 | $version->DiffContent = DBField::create_field('HTMLText', null); |
||
| 110 | $version->DiffContent->setValue('<div>'.$diffContent.'</div>'); |
||
| 111 | $changed = true; |
||
| 112 | } |
||
| 113 | |||
| 114 | // Copy the link so it can be cached. |
||
| 115 | $version->GeneratedLink = $version->AbsoluteLink(); |
||
| 116 | } |
||
| 117 | |||
| 118 | // Omit the versions that haven't been visibly changed (only takes the above fields into consideration). |
||
| 119 | if ($changed) { |
||
| 120 | $changeList->push($version); |
||
| 121 | $count++; |
||
| 122 | } |
||
| 123 | |||
| 124 | // Store the last version for comparison. |
||
| 125 | $previous = $version; |
||
| 126 | } |
||
| 127 | |||
| 128 | // Make sure enough diff items have been generated to satisfy the $limit. If we ran out, add the final, |
||
| 129 | // non-diffed item (the initial version). This will also work for a single-diff request: if we are requesting |
||
| 130 | // a diff on the initial version we will just get that version, verbatim. |
||
| 131 | if ($previous && $versions->count()<$qLimit) { |
||
| 132 | $first = clone($previous); |
||
| 133 | $first->DiffContent = DBField::create_field('HTMLText', null); |
||
| 134 | $first->DiffContent->setValue('<div>' . $first->Content . '</div>'); |
||
| 135 | // Copy the link so it can be cached. |
||
| 136 | $first->GeneratedLink = $first->AbsoluteLink(); |
||
| 137 | $changeList->push($first); |
||
| 138 | } |
||
| 139 | |||
| 140 | return $changeList; |
||
| 141 | } |
||
| 219 |