Completed
Pull Request — master (#7)
by Daniel
01:55
created

Query::comparison()   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 3
1
<?php
2
3
namespace Psi\Component\ObjectAgent\Query;
4
5
/**
6
 * Query::from(Foo::class)
7
 *   ->where(
8
 *       Query::and(
9
 *           Query::comparison('eq', 'foo', 'bar'),
10
 *           Query::comparison('gt', 10, 5),
11
 *       )
12
 *   );.
13
 */
14
final class Query
15
{
16
    private $classFqn;
17
    private $expression;
18
    private $orderings;
19
    private $firstResult;
20
    private $maxResults;
21
22
    public function __construct(
23
        string $classFqn,
24
        Expression $expression = null,
25
        array $orderings = null,
26
        int $firstResult = null,
27
        int $maxResults = null
28
    )
29
    {
30
        $this->classFqn = $classFqn;
31
        $this->expression = $expression;
32
        $this->orderings = $orderings;
33
        $this->firstResult = $firstResult;
34
        $this->maxResults = $maxResults;
35
    }
36
37
    public static function create(
38
        string $classFqn,
39
        Expression $expression = null,
40
        array $orderings = [],
41
        int $firstResult = null,
42
        int $maxResults = null
43
    )
44
    {
45
        return new self($classFqn, $expression, $orderings, $firstResult, $maxResults);
46
    }
47
48
    public static function comparison(string $comparator, $value1, $value2): Comparison
49
    {
50
        return new Comparison($comparator, $value1, $value2);
51
    }
52
53
    public static function composite(string $type, ...$expressions): Composite
54
    {
55
        return new Composite($type, $expressions);
56
    }
57
58
    public function getClassFqn(): string
59
    {
60
        return $this->classFqn;
61
    }
62
63
    public function hasExpression()
64
    {
65
        return null !== $this->expression;
66
    }
67
68
    public function getExpression(): Expression
69
    {
70
        return $this->expression;
71
    }
72
73
    public function getOrderings(): array
74
    {
75
        return $this->orderings;
76
    }
77
78
    public function getMaxResults() 
79
    {
80
        return $this->maxResults;
81
    }
82
83
    public function getFirstResult()
84
    {
85
        return $this->firstResult;
86
    }
87
    
88
    
89
90
}
91