Conditions | 23 |
Paths | 66 |
Total Lines | 105 |
Code Lines | 80 |
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 |
||
80 | public function getItemRating($itemid = 0, $source = 0) |
||
81 | { |
||
82 | $helper = \XoopsModules\Modulebuilder\Helper::getInstance(); |
||
83 | |||
84 | $ItemRating = []; |
||
85 | $ItemRating['nb_ratings'] = 0; |
||
86 | $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
87 | $voted = false; |
||
88 | $ip = getenv('REMOTE_ADDR'); |
||
89 | $current_rating = 0; |
||
90 | |||
91 | if (Constants::RATING_5STARS === (int)$helper->getConfig('ratingbars') |
||
|
|||
92 | || Constants::RATING_10STARS === (int)$helper->getConfig('ratingbars') |
||
93 | || Constants::RATING_10NUM === (int)$helper->getConfig('ratingbars')) { |
||
94 | $rating_unitwidth = 25; |
||
95 | if (Constants::RATING_5STARS === (int)$helper->getConfig('ratingbars')) { |
||
96 | $max_units = 5; |
||
97 | } else { |
||
98 | $max_units = 10; |
||
99 | } |
||
100 | |||
101 | $criteria = new \CriteriaCompo(); |
||
102 | $criteria->add(new \Criteria('rate_itemid', $itemid)); |
||
103 | $criteria->add(new \Criteria('rate_source', $source)); |
||
104 | |||
105 | $ratingObjs = $helper->getHandler('ratings')->getObjects($criteria); |
||
106 | $count = count($ratingObjs); |
||
107 | $ItemRating['nb_ratings'] = $count; |
||
108 | |||
109 | foreach ($ratingObjs as $ratingObj) { |
||
110 | $current_rating += $ratingObj->getVar('rate_value'); |
||
111 | if (($ratingObj->getVar('rate_ip') == $ip && $uid == 0) || ($uid > 0 && $uid == $ratingObj->getVar('rate_uid'))) { |
||
112 | $voted = true; |
||
113 | $ItemRating['id'] = $ratingObj->getVar('rate_id'); |
||
114 | } |
||
115 | } |
||
116 | unset($ratingObj); |
||
117 | unset($criteria); |
||
118 | |||
119 | $ItemRating['avg_rate_value'] = 0; |
||
120 | if ($count > 0) { |
||
121 | $ItemRating['avg_rate_value'] = number_format($current_rating / $count, 2); |
||
122 | } |
||
123 | if (1 == $count) { |
||
124 | $text = str_replace('%c', $ItemRating['avg_rate_value'], _MA_MODULEBUILDER_RATING_CURRENT_1); |
||
125 | $shorttext = str_replace('%c', $ItemRating['avg_rate_value'], _MA_MODULEBUILDER_RATING_CURRENT_SHORT_1); |
||
126 | } else { |
||
127 | $text = str_replace('%c', $ItemRating['avg_rate_value'], _MA_MODULEBUILDER_RATING_CURRENT_X); |
||
128 | $shorttext = str_replace('%c', $ItemRating['avg_rate_value'], _MA_MODULEBUILDER_RATING_CURRENT_SHORT_X); |
||
129 | } |
||
130 | $text = str_replace('%m', $max_units, $text); |
||
131 | $text = str_replace('%t', $ItemRating['nb_ratings'], $text); |
||
132 | $shorttext = str_replace('%t', $ItemRating['nb_ratings'], $shorttext); |
||
133 | $ItemRating['text'] = $text; |
||
134 | $ItemRating['shorttext'] = $shorttext; |
||
135 | $ItemRating['size'] = ($ItemRating['avg_rate_value'] * $rating_unitwidth) . 'px'; |
||
136 | $ItemRating['maxsize'] = ($max_units * $rating_unitwidth) . 'px'; |
||
137 | } else { |
||
138 | $criteria = new \CriteriaCompo(); |
||
139 | $criteria->add(new \Criteria('rate_itemid', $itemid)); |
||
140 | $criteria->add(new \Criteria('rate_source', $source)); |
||
141 | $criteria->add(new \Criteria('rate_value', 0, '<')); |
||
142 | |||
143 | $ratingObjs = $helper->getHandler('ratings')->getObjects($criteria); |
||
144 | $count = count($ratingObjs); |
||
145 | |||
146 | foreach ($ratingObjs as $ratingObj) { |
||
147 | $current_rating += $ratingObj->getVar('rate_value'); |
||
148 | if (($ratingObj->getVar('rate_ip') == $ip && $uid == 0) || ($uid > 0 && $uid == $ratingObj->getVar('rate_uid'))) { |
||
149 | $voted = true; |
||
150 | $ItemRating['id'] = $ratingObj->getVar('rate_id'); |
||
151 | } |
||
152 | } |
||
153 | unset($ratingObj); |
||
154 | unset($criteria); |
||
155 | $ItemRating['dislikes'] = $count; |
||
156 | |||
157 | $criteria = new \CriteriaCompo(); |
||
158 | $criteria->add(new \Criteria('rate_itemid', $itemid)); |
||
159 | $criteria->add(new \Criteria('rate_source', $source)); |
||
160 | $criteria->add(new \Criteria('rate_value', 0, '>')); |
||
161 | |||
162 | $ratingObjs = $helper->getHandler('ratings')->getObjects($criteria); |
||
163 | $count = count($ratingObjs); |
||
164 | $current_rating = 0; |
||
165 | foreach ($ratingObjs as $ratingObj) { |
||
166 | $current_rating += $ratingObj->getVar('rate_value'); |
||
167 | if (($ratingObj->getVar('rate_ip') == $ip && $uid == 0) || ($uid > 0 && $uid == $ratingObj->getVar('rate_uid'))) { |
||
168 | $voted = true; |
||
169 | $ItemRating['id'] = $ratingObj->getVar('rate_id'); |
||
170 | } |
||
171 | } |
||
172 | unset($ratingObj); |
||
173 | unset($criteria); |
||
174 | $ItemRating['likes'] = $count; |
||
175 | |||
176 | $count = $ItemRating['likes'] + $ItemRating['dislikes']; |
||
177 | } |
||
178 | |||
179 | $ItemRating['uid'] = $uid; |
||
180 | $ItemRating['nb_ratings'] = $count; |
||
181 | $ItemRating['voted'] = $voted; |
||
182 | $ItemRating['ip'] = $ip; |
||
183 | |||
184 | return $ItemRating; |
||
185 | } |
||
221 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths