| Conditions | 5 |
| Paths | 3 |
| Total Lines | 55 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 31 | public function rss() |
||
| 32 | { |
||
| 33 | $path = $this->request->getPathWithoutControllerAction(); |
||
| 34 | $configs = $this->getConfigs(); |
||
|
|
|||
| 35 | |||
| 36 | // build model data |
||
| 37 | $model = new EntityCategoryList($path, $configs, 0); |
||
| 38 | // remove global layout |
||
| 39 | $this->layout = null; |
||
| 40 | |||
| 41 | // check if rss display allowed for this category |
||
| 42 | if ((int)$model->category['configs']['showRss'] !== 1) { |
||
| 43 | throw new ForbiddenException(__('Rss feed is disabled for this category')); |
||
| 44 | } |
||
| 45 | |||
| 46 | // set rss/xml header |
||
| 47 | $this->response->headers->set('Content-Type', 'application/rss+xml'); |
||
| 48 | |||
| 49 | // initialize rss feed objects |
||
| 50 | $feed = new Feed(); |
||
| 51 | $channel = new Channel(); |
||
| 52 | |||
| 53 | // set channel data |
||
| 54 | $channel->title($model->category['title']) |
||
| 55 | ->description($model->category['description']) |
||
| 56 | ->url(App::$Alias->baseUrl . '/content/list/' . $model->category['path']) |
||
| 57 | ->appendTo($feed); |
||
| 58 | |||
| 59 | // add content data |
||
| 60 | if ($model->getContentCount() > 0) { |
||
| 61 | foreach ($model->items as $row) { |
||
| 62 | $item = new Item(); |
||
| 63 | // add title, short text, url |
||
| 64 | $item->title($row['title']) |
||
| 65 | ->description($row['text']) |
||
| 66 | ->url(App::$Alias->baseUrl . $row['uri']); |
||
| 67 | // add poster |
||
| 68 | if ($row['thumb'] !== null) { |
||
| 69 | $item->enclosure(App::$Alias->scriptUrl . $row['thumb'], $row['thumbSize'], 'image/jpeg'); |
||
| 70 | } |
||
| 71 | |||
| 72 | // append response to channel |
||
| 73 | $item->appendTo($channel); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | // define rss read event |
||
| 77 | App::$Event->run(static::EVENT_RSS_READ, [ |
||
| 78 | 'model' => $model, |
||
| 79 | 'feed' => $feed, |
||
| 80 | 'channel' => $channel |
||
| 81 | ]); |
||
| 82 | |||
| 83 | // render response from feed object |
||
| 84 | return $feed->render(); |
||
| 85 | } |
||
| 86 | } |
||
| 87 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.