Conditions | 1 |
Paths | 1 |
Total Lines | 27 |
Code Lines | 8 |
Lines | 27 |
Ratio | 100 % |
Changes | 0 |
1 | <?php |
||
5 | public function withMatchActivity() |
||
6 | { |
||
7 | /** @var BaseModel $type */ |
||
8 | $type = $this->type; |
||
9 | $columns = $type::getEagerColumns($this->getFromAlias()); |
||
10 | |||
11 | $this->columns['activity'] = 'activity'; |
||
12 | $this->extraColumns = 'SUM(m2.activity) AS activity'; |
||
13 | $this->extras .= ' |
||
14 | LEFT JOIN |
||
15 | (SELECT |
||
16 | m.id, |
||
17 | m.team_a, |
||
18 | m.team_b, |
||
19 | TIMESTAMPDIFF(SECOND, timestamp, NOW()) / 86400 AS days_passed, |
||
20 | (0.0116687059537612 * (POW((45 - LEAST((SELECT days_passed), 45)), (1/6)) + ATAN(31 - (SELECT days_passed)) / 2)) AS activity |
||
21 | FROM |
||
22 | matches m |
||
23 | WHERE |
||
24 | DATEDIFF(NOW(), timestamp) <= 45 |
||
25 | ORDER BY |
||
26 | timestamp DESC) m2 ON teams.id = m2.team_a OR teams.id = m2.team_b |
||
27 | '; |
||
28 | $this->groupQuery = 'GROUP BY ' . $columns; |
||
29 | |||
30 | return $this; |
||
31 | } |
||
32 | } |
||
33 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.