| Conditions | 10 |
| Paths | 2 |
| Total Lines | 45 |
| 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 |
||
| 44 | public function indexAction() |
||
| 45 | { |
||
| 46 | $this->view->setRenderLevel( \Phalcon\Mvc\View::LEVEL_NO_RENDER ); |
||
| 47 | $cache = $this->getDi()->get('cache'); |
||
|
|
|||
| 48 | $sitemap_xml = $cache->get($this->cacheViewKey); |
||
| 49 | |||
| 50 | if(!$sitemap_xml){ |
||
| 51 | $langs = Language::find(['columns' => 'iso,primary']); |
||
| 52 | |||
| 53 | //link(s) for main-page(s) |
||
| 54 | foreach ($langs as $lang){ |
||
| 55 | $suffix = !$lang['primary'] ? $lang['iso'] . '/' : ''; |
||
| 56 | $this->links[] = [ |
||
| 57 | 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/' . $suffix, |
||
| 58 | 'updated_at' => date('c',time()), |
||
| 59 | ]; |
||
| 60 | } |
||
| 61 | |||
| 62 | foreach ($this->models as $m) { |
||
| 63 | $class_name = '\\' . $m['class'] . '\Model\\' . $m['model']; |
||
| 64 | $where = !empty($m['where']) ? $m['where'] : ''; |
||
| 65 | |||
| 66 | $rows = $class_name::find($where); |
||
| 67 | |||
| 68 | foreach ($langs as $lang) { |
||
| 69 | foreach ($rows as $row) { |
||
| 70 | $row::setCustomLang($lang->iso); |
||
| 71 | if($row->getSlug() !== 'index' && $row->getTitle()){ |
||
| 72 | $this->links[] = [ |
||
| 73 | 'url' => 'http://' . $_SERVER['HTTP_HOST'] . $m['getLink']($row, $lang->iso), |
||
| 74 | 'updated_at' => date('c', strtotime($row->getUpdatedAt())), |
||
| 75 | ]; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | $sitemap_xml = $this->getRawXml(); |
||
| 81 | $cache->save($this->cacheViewKey, $sitemap_xml); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | $this->response->setHeader("Content-Type", "text/xml"); |
||
| 86 | $this->response->setContent($sitemap_xml); |
||
| 87 | return $this->response->send(); |
||
| 88 | } |
||
| 89 | |||
| 109 | } |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.