| Conditions | 12 |
| Paths | 20 |
| Total Lines | 66 |
| Code Lines | 48 |
| 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 |
||
| 28 | public function index(string $name, ?string $value = null): ?string |
||
| 29 | { |
||
| 30 | $records = null; |
||
| 31 | // set current page and offset |
||
| 32 | $page = (int)$this->request->query->get('page', 0); |
||
| 33 | $cfgs = $this->application->configs; |
||
| 34 | $userPerPage = (int)$cfgs['usersOnPage']; |
||
| 35 | if ($userPerPage < 1) { |
||
| 36 | $userPerPage = 1; |
||
| 37 | } |
||
| 38 | $offset = $page * $userPerPage; |
||
| 39 | |||
| 40 | switch ($name) { |
||
| 41 | case 'rating': // rating list, order by rating DESC |
||
| 42 | // check if rating is enabled |
||
| 43 | if ((int)$cfgs['rating'] !== 1) { |
||
| 44 | throw new NotFoundException(); |
||
| 45 | } |
||
| 46 | $records = (new ProfileRecords())->orderBy('rating', 'DESC'); |
||
| 47 | break; |
||
| 48 | case 'hobby': // search by hobby |
||
| 49 | if (Str::likeEmpty($value)) { |
||
| 50 | throw new NotFoundException(); |
||
| 51 | } |
||
| 52 | $records = (new ProfileRecords())->where('hobby', 'like', '%' . $value . '%'); |
||
| 53 | break; |
||
| 54 | case 'city': |
||
| 55 | if (Str::likeEmpty($value)) { |
||
| 56 | throw new NotFoundException(); |
||
| 57 | } |
||
| 58 | $records = (new ProfileRecords())->where('city', $value); |
||
| 59 | break; |
||
| 60 | case 'born': |
||
| 61 | if ($value === null || !Any::isInt($value)) { |
||
| 62 | throw new NotFoundException(); |
||
| 63 | } |
||
| 64 | $records = (new ProfileRecords())->where('birthday', 'like', $value . '-%'); |
||
| 65 | break; |
||
| 66 | case 'all': |
||
| 67 | $records = (new ProfileRecords())->orderBy('id', 'DESC'); |
||
| 68 | break; |
||
| 69 | default: |
||
| 70 | $this->response->redirect('profile/index/all'); |
||
| 71 | break; |
||
| 72 | } |
||
| 73 | |||
| 74 | // get total records count |
||
| 75 | $totalCount = $records->count(); |
||
| 76 | |||
| 77 | // get profile list with relation for user and role tables in 1 query |
||
| 78 | $profiles = $records->with(['user', 'user.role']) |
||
| 79 | ->skip($offset) |
||
| 80 | ->take($userPerPage) |
||
| 81 | ->get(); |
||
| 82 | |||
| 83 | // render output view |
||
| 84 | return $this->view->render('profile/index', [ |
||
| 85 | 'records' => $profiles, |
||
| 86 | 'pagination' => [ |
||
| 87 | 'page' => $page, |
||
| 88 | 'total' => $totalCount, |
||
| 89 | 'step' => $userPerPage |
||
| 90 | ], |
||
| 91 | 'id' => $name, |
||
| 92 | 'add' => $value, |
||
| 93 | 'ratingOn' => (int)$cfgs['rating'] |
||
| 94 | ]); |
||
| 97 |
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