Completed
Push — feature/sass-standard ( 554da1...a5bd48 )
by Vladimir
12:37 queued 09:02
created

ConversationQueryBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 28.95 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 11
loc 38
ccs 5
cts 10
cp 0.5
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forPlayer() 11 11 1
A forTeam() 0 11 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
 * This file contains a class to quickly generate database queries for conversations
4
 *
5
 * @package    BZiON\Models\QueryBuilder
6
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
7
 */
8
9
/**
10
 * This class can be used to search for conversations  with specific
11
 * characteristics in the database.
12
 *
13
 * @package    BZiON\Models\QueryBuilder
14
 */
15
class ConversationQueryBuilder extends QueryBuilder
16
{
17
    /**
18
     * Only return messages that are sent from/to a specific player
19
     *
20
     * @param  Player $player The player related to the messages
21
     * @return self
22
     */
23 1 View Code Duplication
    public function forPlayer($player)
0 ignored issues
show
Duplication introduced by
This method 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...
24
    {
25 1
        $this->extras .= '
26
            LEFT JOIN player_conversations ON player_conversations.conversation=conversations.id
27
        ';
28
29 1
        $this->column('player_conversations.player')->is($player);
30 1
        $this->column('conversations.status')->isOneOf(Conversation::getActiveStatuses());
31
32 1
        return $this;
33
    }
34
35
    /**
36
     * Only return messages that are sent from/to a specific team
37
     *
38
     * @param  Team $team The team related to the messages
39
     * @return self
40
     */
41
    public function forTeam($team)
42
    {
43
        $this->extras .= '
44
            LEFT JOIN team_conversations ON team_conversations.conversation=conversations.id
45
        ';
46
47
        $this->column('team_conversations.team')->is($team);
48
        $this->column('conversations.status')->notEquals('deleted');
49
50
        return $this;
51
    }
52
}
53