Comparison::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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