| Conditions | 9 |
| Paths | 49 |
| Total Lines | 73 |
| 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 |
||
| 151 | public function doGET($request) |
||
| 152 | { |
||
| 153 | self::$logger->debug('>>doGET($request=['.var_export($request, true).'])'); |
||
| 154 | |||
| 155 | $config = ConfigProvider::getInstance(); |
||
| 156 | |||
| 157 | $params = $request->getParams(); |
||
| 158 | |||
| 159 | $response = new Response(200); |
||
| 160 | |||
| 161 | try { |
||
| 162 | if (isset($params['ActiveRecordType'])) { |
||
| 163 | $ActiveRecordType = urldecode($params['ActiveRecordType']); |
||
| 164 | } else { |
||
| 165 | throw new IllegalArguementException('ActiveRecordType not specified to generate feed!'); |
||
| 166 | } |
||
| 167 | |||
| 168 | if (isset($params['type'])) { |
||
| 169 | $type = $params['type']; |
||
| 170 | } else { |
||
| 171 | throw new IllegalArguementException('No feed type specified to generate feed!'); |
||
| 172 | } |
||
| 173 | |||
| 174 | if (class_exists($ActiveRecordType)) { |
||
| 175 | $this->ActiveRecordType = $ActiveRecordType; |
||
| 176 | } else { |
||
| 177 | throw new IllegalArguementException('No ActiveRecord available to render!'); |
||
| 178 | } |
||
| 179 | $this->type = $type; |
||
| 180 | |||
| 181 | $this->setup(); |
||
| 182 | |||
| 183 | $feed = null; |
||
| 184 | |||
| 185 | switch ($type) { |
||
| 186 | case 'RSS2': |
||
| 187 | $feed = new RSS2($this->ActiveRecordType, $this->title, str_replace('&', '&', $request->getURI()), $this->description); |
||
| 188 | $feed->setFieldMappings($this->fieldMappings[0], $this->fieldMappings[1], $this->fieldMappings[2], $this->fieldMappings[3]); |
||
| 189 | $response->setHeader('Content-Type', 'application/rss+xml'); |
||
| 190 | break; |
||
| 191 | case 'RSS': |
||
| 192 | $feed = new RSS($this->ActiveRecordType, $this->title, str_replace('&', '&', $request->getURI()), $this->description); |
||
| 193 | $feed->setFieldMappings($this->fieldMappings[0], $this->fieldMappings[1], $this->fieldMappings[2], $this->fieldMappings[3]); |
||
| 194 | $response->setHeader('Content-Type', 'application/rss+xml'); |
||
| 195 | break; |
||
| 196 | case 'Atom': |
||
| 197 | $feed = new Atom($this->ActiveRecordType, $this->title, str_replace('&', '&', $request->getURI()), $this->description); |
||
| 198 | $feed->setFieldMappings($this->fieldMappings[0], $this->fieldMappings[1], $this->fieldMappings[2], $this->fieldMappings[3], |
||
| 199 | $this->fieldMappings[4]); |
||
| 200 | if ($config->get('feeds.atom.author') != '') { |
||
| 201 | $feed->addAuthor($config->get('feeds.atom.author')); |
||
| 202 | } |
||
| 203 | $response->setHeader('Content-Type', 'application/atom+xml'); |
||
| 204 | break; |
||
| 205 | } |
||
| 206 | |||
| 207 | // now add the twenty last items (from newest to oldest) to the feed, and render |
||
| 208 | $feed->loadRecords(20, $this->sortBy); |
||
| 209 | $response->setBody($feed->render()); |
||
| 210 | |||
| 211 | // log the request for this news feed |
||
| 212 | $feedLog = new LogProviderFile(); |
||
| 213 | $feedLog->setPath($config->get('app.file.store.dir').'logs/feeds.log'); |
||
| 214 | $feedLog->writeLine(array($this->ActiveRecordType, $this->type, date('Y-m-d H:i:s'), $request->getUserAgent(), $request->getIP())); |
||
| 215 | } catch (IllegalArguementException $e) { |
||
| 216 | self::$logger->error($e->getMessage()); |
||
| 217 | throw new ResourceNotFoundException($e->getMessage()); |
||
| 218 | } |
||
| 219 | |||
| 220 | self::$logger->debug('<<doGet'); |
||
| 221 | |||
| 222 | return $response; |
||
| 223 | } |
||
| 224 | |||
| 246 |