GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f54b59...2b88e7 )
by Rik
05:03 queued 02:46
created

GroupBy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 21.82 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 2
dl 12
loc 55
c 1
b 0
f 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A modify() 0 9 1
A setType() 12 12 2

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
namespace Rb\Specification\Doctrine\Query;
4
5
use Doctrine\ORM\QueryBuilder;
6
use Rb\Specification\Doctrine\AbstractSpecification;
7
use Rb\Specification\Doctrine\Exception\InvalidArgumentException;
8
9
10
/**
11
 * @author  Kyle Tucker <[email protected]>
12
 */
13
class GroupBy extends AbstractSpecification
14
{
15
    const GROUP_BY     = 'groupBy';
16
    const ADD_GROUP_BY = 'addGroupBy';
17
18
    /** @var  string[]  */
19
    protected static $types = [self::GROUP_BY, self::ADD_GROUP_BY];
20
21
    /** @var  string */
22
    protected $type;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param  string       $field
28
     * @param  string       $type
29
     * @param  string|null  $dqlAlias
30
     */
31
    public function __construct($field, $type = self::ADD_GROUP_BY, $dqlAlias = null)
32
    {
33
        $this->setType($type);
34
        parent::__construct($field, $dqlAlias);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function modify(QueryBuilder $queryBuilder, $dqlAlias)
41
    {
42
        call_user_func_array(
43
            [$queryBuilder, $this->type],
44
            [
45
                $this->createPropertyWithAlias($dqlAlias),
46
            ]
47
        );
48
    }
49
50
    /**
51
     * @param  string  $type
52
     *
53
     * @throws  InvalidArgumentException
54
     */
55 View Code Duplication
    public function setType($type)
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...
56
    {
57
        if (!in_array($type, self::$types)) {
58
            throw new InvalidArgumentException(sprintf(
59
                '"%s" is not a valid type! Valid types: %s',
60
                $type,
61
                implode(', ', self::$types)
62
            ));
63
        }
64
65
        $this->type = $type;
66
    }
67
}
68