| Conditions | 1 |
| Paths | 1 |
| Total Lines | 96 |
| Code Lines | 34 |
| 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 |
||
| 45 | public function getTagMentions(int $limit = 0): DataReaderInterface |
||
| 46 | { |
||
| 47 | /** @var Repository $postTagRepo */ |
||
| 48 | $postTagRepo = $this->orm->getRepository(PostTag::class); |
||
| 49 | /** @var PostRepository $postRepo */ |
||
| 50 | $postRepo = $this->orm->getRepository(Post::class); |
||
| 51 | |||
| 52 | // For example, below are several ways to make queries |
||
| 53 | // As a result, we should get a list of most used tags |
||
| 54 | // All SQL-queries received on mysql database. SQL-queries may vary by driver |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Case 1 would look like:. |
||
| 58 | * |
||
| 59 | * SELECT `t`.`label`, count(*) `count` |
||
| 60 | * FROM `post_tag` AS `postTag` |
||
| 61 | * INNER JOIN `post` AS `p` |
||
| 62 | * ON `p`.`id` = `postTag`.`post_id` AND `p`.`public` = TRUE |
||
| 63 | * INNER JOIN `tag` AS `t` |
||
| 64 | * ON `t`.`id` = `postTag`.`tag_id` |
||
| 65 | * GROUP BY `t`.`label`, `tag_id` |
||
| 66 | * ORDER BY `count` DESC |
||
| 67 | */ |
||
| 68 | $case1 = $postTagRepo |
||
| 69 | ->select() |
||
| 70 | ->buildQuery() |
||
| 71 | ->columns(['t.label', 'count(*) count']) |
||
| 72 | ->innerJoin('post', 'p') |
||
| 73 | ->on('p.id', 'postTag.post_id') |
||
| 74 | ->onWhere(['p.public' => true]) |
||
| 75 | ->innerJoin('tag', 't') |
||
| 76 | ->on('t.id', 'postTag.tag_id') |
||
| 77 | ->groupBy('t.label, tag_id'); |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Case 2 would look like:. |
||
| 81 | * |
||
| 82 | * SELECT `label`, count(*) `count` |
||
| 83 | * FROM `tag` AS `tag` |
||
| 84 | * INNER JOIN `post_tag` AS `tag_posts_pivot` |
||
| 85 | * ON `tag_posts_pivot`.`tag_id` = `tag`.`id` |
||
| 86 | * INNER JOIN `post` AS `tag_posts` |
||
| 87 | * ON `tag_posts`.`id` = `tag_posts_pivot`.`post_id` AND `tag_posts`.`public` = TRUE |
||
| 88 | * GROUP BY `tag`.`label`, `tag_id` |
||
| 89 | * ORDER BY `count` DESC |
||
| 90 | */ |
||
| 91 | $case2 = $this |
||
| 92 | ->select() |
||
| 93 | ->with('posts') |
||
| 94 | ->buildQuery() |
||
| 95 | ->columns(['label', 'count(*) count']) |
||
| 96 | ->groupBy('tag.label, tag_id'); |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Case 3 would look like:. |
||
| 100 | * |
||
| 101 | * SELECT `label`, count(*) `count` |
||
| 102 | * FROM `tag` AS `tag` |
||
| 103 | * INNER JOIN `post_tag` AS `tag_posts_pivot` |
||
| 104 | * ON `tag_posts_pivot`.`tag_id` = `tag`.`id` |
||
| 105 | * INNER JOIN `post` AS `tag_posts` |
||
| 106 | * ON `tag_posts`.`id` = `tag_posts_pivot`.`post_id` AND `tag_posts`.`public` = TRUE |
||
| 107 | * GROUP BY `tag_posts_pivot`.`tag_id`, `tag`.`label` |
||
| 108 | * ORDER BY `count` DESC |
||
| 109 | */ |
||
| 110 | $case3 = $this |
||
| 111 | ->select() |
||
| 112 | ->groupBy('[email protected]_id') // relation posts -> pivot (@) -> column |
||
| 113 | ->groupBy('label') |
||
| 114 | ->buildQuery() |
||
| 115 | ->columns(['label', 'count(*) count']); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Case 4 would look like:. |
||
| 119 | * |
||
| 120 | * SELECT `label`, count(*) `count` |
||
| 121 | * FROM `post` AS `post` |
||
| 122 | * INNER JOIN `post_tag` AS `post_tags_pivot` |
||
| 123 | * ON `post_tags_pivot`.`post_id` = `post`.`id` |
||
| 124 | * INNER JOIN `tag` AS `post_tags` |
||
| 125 | * ON `post_tags`.`id` = `post_tags_pivot`.`tag_id` |
||
| 126 | * WHERE `post`.`public` = TRUE |
||
| 127 | * GROUP BY `post_tags_pivot`.`tag_id`, `tag`.`label` |
||
| 128 | */ |
||
| 129 | $case4 = $postRepo |
||
| 130 | ->select() |
||
| 131 | ->groupBy('[email protected]_id') // relation tags -> pivot (@) -> column |
||
| 132 | ->groupBy('tags.label') |
||
| 133 | ->buildQuery() |
||
| 134 | ->columns(['label', 'count(*) count']); |
||
| 135 | |||
| 136 | $sort = Sort::only(['count', 'label'])->withOrder(['count' => 'desc']); |
||
| 137 | |||
| 138 | return (new EntityReader($case3)) |
||
| 139 | ->withSort($sort) |
||
| 140 | ->withLimit($limit); |
||
| 141 | } |
||
| 143 |
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