Completed
Push — master ( d1b735...0bfc48 )
by Daniel
08:29
created

Comparison::getValue()   A

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
16
    // TODO: Contains (like), NULL, NOT NULL, IN
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
17
18
    private static $validTypes = [
19
        self::EQUALS,
20
        self::NOT_EQUALS,
21
        self::GREATER_THAN,
22
        self::GREATER_THAN_EQUAL,
23
        self::LESS_THAN,
24
        self::LESS_THAN_EQUAL,
25
    ];
26
27
    private $comparator;
28
    private $field;
29
    private $value;
30
31 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...
32
    {
33
        if (!in_array($comparator, self::$validTypes)) {
34
            throw new \InvalidArgumentException(sprintf(
35
                'Unknown comparator "%s". Known comparators: "%s"',
36
                $comparator,
37
                implode('", "', self::$validTypes)
38
            ));
39
        }
40
41
        $this->comparator = $comparator;
42
        $this->field = $field;
43
        $this->value = $value;
44
    }
45
46
    public function getComparator()
47
    {
48
        return $this->comparator;
49
    }
50
51
    public function getField()
52
    {
53
        return $this->field;
54
    }
55
56
    public function getValue()
57
    {
58
        return $this->value;
59
    }
60
}
61