| Conditions | 9 |
| Paths | 52 |
| Total Lines | 70 |
| Code Lines | 40 |
| 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 |
||
| 177 | public static function ExtractMonths( |
||
| 178 | DataList $updates, |
||
| 179 | $link = null, |
||
| 180 | $currentYear = null, |
||
| 181 | $currentMonthNumber = null |
||
| 182 | ) { |
||
| 183 | // Set the link to current URL in the same way the HTTP::setGetVar does it. |
||
| 184 | if (!isset($link)) { |
||
| 185 | $link = Director::makeRelative($_SERVER['REQUEST_URI']); |
||
| 186 | } |
||
| 187 | |||
| 188 | $dates = $updates->dataQuery() |
||
| 189 | ->groupby('YEAR("Date")') |
||
| 190 | ->groupby('MONTH("Date")') |
||
| 191 | ->query() |
||
| 192 | ->setSelect([ |
||
| 193 | 'Year' => 'YEAR("Date")', |
||
| 194 | 'Month' => 'MONTH("Date")', |
||
| 195 | ]) |
||
| 196 | ->addWhere('"Date" IS NOT NULL') |
||
| 197 | ->setOrderBy([ |
||
| 198 | 'YEAR("Date")' => 'DESC', |
||
| 199 | 'MONTH("Date")' => 'DESC', |
||
| 200 | ]) |
||
| 201 | ->execute(); |
||
| 202 | |||
| 203 | $years = []; |
||
| 204 | foreach ($dates as $date) { |
||
| 205 | $monthNumber = $date['Month']; |
||
| 206 | $year = $date['Year']; |
||
| 207 | $dateObj = new DateTime(implode('-', [$year, $monthNumber, 1])); |
||
| 208 | $monthName = $dateObj->Format('M'); |
||
| 209 | |||
| 210 | // Set up the relevant year array, if not yet available. |
||
| 211 | if (!isset($years[$year])) { |
||
| 212 | $years[$year] = ['YearName'=>$year, 'Months' => []]; |
||
| 213 | } |
||
| 214 | |||
| 215 | // Check if the currently processed month is the one that is selected via GET params. |
||
| 216 | $active = false; |
||
| 217 | if (isset($year) && isset($monthNumber)) { |
||
| 218 | $active = (((int)$currentYear)==$year && ((int)$currentMonthNumber)==$monthNumber); |
||
| 219 | } |
||
| 220 | |||
| 221 | // Build the link - keep the tag and date filter, but reset the pagination. |
||
| 222 | if ($active) { |
||
| 223 | // Allow clicking to deselect the month. |
||
| 224 | $link = HTTP::setGetVar('month', null, $link, '&'); |
||
| 225 | $link = HTTP::setGetVar('year', null, $link, '&'); |
||
| 226 | } else { |
||
| 227 | $link = HTTP::setGetVar('month', $monthNumber, $link, '&'); |
||
| 228 | $link = HTTP::setGetVar('year', $year, $link, '&'); |
||
| 229 | } |
||
| 230 | $link = HTTP::setGetVar('start', null, $link, '&'); |
||
| 231 | |||
| 232 | $years[$year]['Months'][$monthNumber] = array( |
||
| 233 | 'MonthName'=>$monthName, |
||
| 234 | 'MonthNumber'=>$monthNumber, |
||
| 235 | 'MonthLink'=>$link, |
||
| 236 | 'Active'=>$active |
||
| 237 | ); |
||
| 238 | } |
||
| 239 | |||
| 240 | // ArrayList will not recursively walk through the supplied array, so manually build nested ArrayLists. |
||
| 241 | foreach ($years as &$year) { |
||
| 242 | $year['Months'] = new ArrayList($year['Months']); |
||
| 243 | } |
||
| 244 | |||
| 245 | // Reverse the list so the most recent years appear first. |
||
| 246 | return new ArrayList($years); |
||
| 247 | } |
||
| 264 |
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