Comparison   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 21.88 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 14
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 2
A getComparator() 0 4 1
A getField() 0 4 1
A getValue() 0 4 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
declare(strict_types=1);
4
5
namespace Psi\Component\ObjectAgent\Query;
6
7
class Comparison implements Expression
8
{
9
    const EQUALS = 'eq';
10
    const NOT_EQUALS = 'neq';
11
    const GREATER_THAN = 'gt';
12
    const GREATER_THAN_EQUAL = 'gte';
13
    const LESS_THAN = 'lt';
14
    const LESS_THAN_EQUAL = 'lte';
15
    const NULL = 'null';
16
    const NOT_NULL = 'not_null';
17
    const IN = 'in';
18
    const NOT_IN = 'nin';
19
    const CONTAINS = 'contains';
20
    const NOT_CONTAINS = 'not_contains';
21
22
    private static $validTypes = [
23
        self::EQUALS,
24
        self::NOT_EQUALS,
25
        self::GREATER_THAN,
26
        self::GREATER_THAN_EQUAL,
27
        self::LESS_THAN,
28
        self::LESS_THAN_EQUAL,
29
        self::NULL,
30
        self::NOT_NULL,
31
        self::IN,
32
        self::NOT_IN,
33
        self::CONTAINS,
34
        self::NOT_CONTAINS,
35
    ];
36
37
    private $comparator;
38
    private $field;
39
    private $value;
40
41 View Code Duplication
    public function __construct(string $comparator, $field, $value)
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...
42
    {
43
        if (!in_array($comparator, self::$validTypes)) {
44
            throw new \InvalidArgumentException(sprintf(
45
                'Unknown comparator "%s". Known comparators: "%s"',
46
                $comparator,
47
                implode('", "', self::$validTypes)
48
            ));
49
        }
50
51
        $this->comparator = $comparator;
52
        $this->field = $field;
53
        $this->value = $value;
54
    }
55
56
    public function getComparator()
57
    {
58
        return $this->comparator;
59
    }
60
61
    public function getField()
62
    {
63
        return $this->field;
64
    }
65
66
    public function getValue()
67
    {
68
        return $this->value;
69
    }
70
}
71