| Conditions | 10 |
| Paths | 3 |
| Total Lines | 58 |
| Code Lines | 32 |
| 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 |
||
| 96 | public function allchanges() |
||
| 97 | { |
||
| 98 | // Check viewability of allchanges |
||
| 99 | if (!Config::inst()->get(VersionFeed::class, 'allchanges_enabled') |
||
| 100 | || !SiteConfig::current_site_config()->AllChangesEnabled |
||
| 101 | ) { |
||
| 102 | return $this->owner->httpError(404, 'Global history not viewable'); |
||
| 103 | } |
||
| 104 | |||
| 105 | $limit = (int)Config::inst()->get(VersionFeed::class, 'allchanges_limit'); |
||
| 106 | $latestChanges = DB::query(' |
||
| 107 | SELECT * FROM "SiteTree_versions" |
||
| 108 | WHERE "WasPublished" = \'1\' |
||
| 109 | AND "CanViewType" IN (\'Anyone\', \'Inherit\') |
||
| 110 | AND "ShowInSearch" = 1 |
||
| 111 | AND ("PublicHistory" IS NULL OR "PublicHistory" = \'1\') |
||
| 112 | ORDER BY "LastEdited" DESC LIMIT ' . $limit); |
||
| 113 | $lastChange = $latestChanges->record(); |
||
| 114 | $latestChanges->rewind(); |
||
| 115 | |||
| 116 | if ($lastChange) { |
||
| 117 | // Cache the diffs to remove DOS possibility. |
||
| 118 | $key = 'allchanges' |
||
| 119 | . preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited']) |
||
| 120 | . (Member::currentUserID() ?: 'public'); |
||
| 121 | $changeList = $this->filterContent($key, function () use ($latestChanges) { |
||
| 122 | $changeList = new ArrayList(); |
||
| 123 | $canView = array(); |
||
| 124 | foreach ($latestChanges as $record) { |
||
| 125 | // Check if the page should be visible. |
||
| 126 | // WARNING: although we are providing historical details, we check the current configuration. |
||
| 127 | $id = $record['RecordID']; |
||
| 128 | if (!isset($canView[$id])) { |
||
| 129 | $page = SiteTree::get()->byID($id); |
||
| 130 | $canView[$id] = $page && $page->canView(new Member()); |
||
| 131 | } |
||
| 132 | if (!$canView[$id]) { |
||
| 133 | continue; |
||
| 134 | } |
||
| 135 | |||
| 136 | // Get the diff to the previous version. |
||
| 137 | $version = new Versioned_Version($record); |
||
| 138 | if ($diff = $version->getDiff()) { |
||
| 139 | $changeList->push($diff); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | return $changeList; |
||
| 144 | }); |
||
| 145 | } else { |
||
| 146 | $changeList = new ArrayList(); |
||
| 147 | } |
||
| 148 | |||
| 149 | // Produce output |
||
| 150 | $url = $this->owner->getRequest()->getURL(); |
||
| 151 | $rss = new RSSFeed($changeList, $url, $this->linkToAllSitesRSSFeedTitle(), '', 'Title', '', null); |
||
| 152 | $rss->setTemplate('Page_allchanges_rss'); |
||
| 153 | return $rss->outputToBrowser(); |
||
| 154 | } |
||
| 200 |