| Conditions | 9 |
| Paths | 34 |
| Total Lines | 57 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 57 | public function show_star_rating($item = null, $registerScript = true) { |
||
| 58 | $this->list_for_show = $this->rating_model->get_settings(); |
||
| 59 | if ($this->list_for_show == null) { |
||
| 60 | $this->list_for_show = []; |
||
| 61 | } |
||
| 62 | $id = $this->core->core_data['id']; |
||
| 63 | $type = $this->core->core_data['data_type']; |
||
| 64 | |||
| 65 | // product rating |
||
| 66 | if ($item != null && $item instanceof SProducts) { |
||
| 67 | if ($item->getRating() != null) { |
||
| 68 | $rating_s = (int) $item->getRating() * 20; // rating in percent |
||
| 69 | } else { |
||
| 70 | $rating_s = 0; |
||
| 71 | } |
||
| 72 | |||
| 73 | $data = [ |
||
| 74 | 'id_type' => $item->getId(), |
||
| 75 | 'type' => 'product', |
||
| 76 | 'votes' => $item->getVotes(), |
||
| 77 | 'rating' => $rating_s |
||
| 78 | ]; |
||
| 79 | $template = 'product_star_rating'; |
||
| 80 | } else { |
||
| 81 | if (in_array($type, array_keys($this->list_for_show))) { |
||
| 82 | $rating = $this->rating_model->get_rating($id, $type); |
||
| 83 | if ($rating->votes != 0) { |
||
| 84 | $rating_s = $rating->rating / $rating->votes * 20; //rating in percent |
||
| 85 | } else { |
||
| 86 | $rating_s = 0; |
||
| 87 | } |
||
| 88 | $data = [ |
||
| 89 | 'id' => $rating->id, |
||
| 90 | 'type' => $rating->type, |
||
| 91 | 'votes' => $rating->votes, |
||
| 92 | 'rating' => $rating_s |
||
| 93 | ]; |
||
| 94 | |||
| 95 | $template = 'star_rating'; |
||
| 96 | } else { |
||
| 97 | $template = null; |
||
| 98 | return false; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | //Show template with prepared parameters |
||
| 103 | if ($template !== null) { |
||
| 104 | $renderTemplate = assetManager::create(); |
||
| 105 | } |
||
| 106 | $renderTemplate->setData($data) |
||
| 107 | ->registerStyle('style'); |
||
| 108 | if ($registerScript) { |
||
| 109 | $renderTemplate->registerScript('scripts'); |
||
| 110 | } |
||
| 111 | $renderTemplate->render($template, true); |
||
| 112 | return $this; |
||
| 113 | } |
||
| 114 | |||
| 230 | } |