Completed
Push — master ( bd48a4...4fe654 )
by Daniel
9s
created

Query::getFirstResult()   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
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
        $this->classFqn = $classFqn;
30
        $this->expression = $expression;
31
        $this->orderings = $orderings;
32
        $this->firstResult = $firstResult;
33
        $this->maxResults = $maxResults;
34
    }
35
36
    public static function create(
37
        string $classFqn,
38
        Expression $expression = null,
39
        array $orderings = [],
40
        int $firstResult = null,
41
        int $maxResults = null
42
    ) {
43
        return new self($classFqn, $expression, $orderings, $firstResult, $maxResults);
44
    }
45
46
    public static function comparison(string $comparator, $value1, $value2): Comparison
47
    {
48
        return new Comparison($comparator, $value1, $value2);
49
    }
50
51
    public static function composite(string $type, ...$expressions): Composite
52
    {
53
        return new Composite($type, $expressions);
54
    }
55
56
    public function getClassFqn(): string
57
    {
58
        return $this->classFqn;
59
    }
60
61
    public function hasExpression()
62
    {
63
        return null !== $this->expression;
64
    }
65
66
    public function getExpression(): Expression
67
    {
68
        return $this->expression;
69
    }
70
71
    public function getOrderings(): array
72
    {
73
        return $this->orderings;
74
    }
75
76
    public function getMaxResults()
77
    {
78
        return $this->maxResults;
79
    }
80
81
    public function getFirstResult()
82
    {
83
        return $this->firstResult;
84
    }
85
}
86