Completed
Push — feature/team-activity ( 2f8466 )
by Vladimir
02:53
created

TeamQueryBuilder   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 30
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B withMatchActivity() 27 27 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3 View Code Duplication
class TeamQueryBuilder extends QueryBuilder
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
4
{
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