Criteria::lessThan()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace MetadataMapping\Query;
6
7
use MetadataMapping\Metadata\DataMap;
8
9
class Criteria
10
{
11
    private $sqlOperator;
12
13
    private $field;
14
15
    private $value;
16
17
    public static function greaterThan(string $field, string $value): self
18
    {
19
        return new self(" > ", $field, $value);
20
    }
21
22
    public static function lessThan(string $field, string $value): self
23
    {
24
        return new self(" < ", $field, $value);
25
    }
26
27 2
    public static function equals(string $field, string $value): self
28
    {
29 2
        return new self(" = ", $field, $value);
30
    }
31
32
    public static function matches(string $field, string $value): self
33
    {
34
        return new self(" LIKE ", $field, $value);
35
    }
36
37 2
    private function __construct(
38
        string $sqlOperator,
39
        string $field,
40
        string $value
41
    ) {
42 2
        $this->sqlOperator = $sqlOperator;
43 2
        $this->field = $field;
44 2
        $this->value = $value;
45 2
    }
46
47 2
    public function generateSql(DataMap $dataMap)
48
    {
49 2
        return sprintf(
50 2
            "%s%s?",
51 2
            $dataMap->getColumnForField($this->field),
52 2
            $this->sqlOperator
53
        );
54
    }
55
56 2
    public function getValue(): string
57
    {
58 2
        return $this->value;
59
    }
60
}
61