Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
19 / 19
CRAP
100.00% covered (success)
100.00%
1 / 1
Query
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
19 / 19
19
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 from
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addFields
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFields
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fields
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addVariables
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 variables
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addCondition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 conditions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addInnerJoin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addJoin
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 joins
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addGroupBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 groupBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addOrderBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 orderBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLimit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 offset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 max
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Dynart\Micro\Entities;
4
5class Query {
6
7    const INNER_JOIN = 'inner';
8    const LEFT_JOIN = 'left';
9    const RIGHT_JOIN = 'right';
10    const OUTER_JOIN = 'full outer';
11
12    protected string|Query $from;
13    protected array $variables = [];
14    protected array $fields = [];
15    protected array $joins = [];
16    protected array $conditions = [];
17    protected array $groups = [];
18    protected array $orders = [];
19    protected int $offset = -1;
20    protected int $max = -1;
21
22    public function __construct(string|Query $from) {
23        $this->from = $from;
24    }
25
26    public function from(): string|Query {
27        return $this->from;
28    }
29
30    public function addFields(array $fields): void {
31        $this->fields = array_merge($this->fields, $fields);
32    }
33
34    public function setFields(array $fields): void {
35        $this->fields = $fields;
36    }
37
38    public function fields(): array {
39        return $this->fields;
40    }
41
42    public function addVariables(array $variables): void {
43        $this->variables = array_merge($this->variables, $variables);
44    }
45
46    public function variables(): array {
47        return $this->variables;
48    }
49
50    public function addCondition(string $condition, array $variables = []): void {
51        $this->conditions[] = $condition;
52        $this->addVariables($variables);
53    }
54
55    public function conditions(): array {
56        return $this->conditions;
57    }
58
59    public function addInnerJoin(string|array $from, string $condition, array $variables = []): void {
60        $this->addJoin(self::INNER_JOIN, $from, $condition, $variables);
61    }
62
63    public function addJoin(string $type, string|array $from, string $condition, array $variables = []): void {
64        $this->joins[] = [$type, $from, $condition];
65        $this->addVariables($variables);
66    }
67
68    public function joins(): array {
69        return $this->joins;
70    }
71
72    public function addGroupBy(string $name): void {
73        $this->groups[] = $name;
74    }
75
76    public function groupBy(): array {
77        return $this->groups;
78    }
79
80    public function addOrderBy(string $name, string $dir = 'asc'): void {
81        $this->orders[] = [$name, $dir];
82    }
83
84    public function orderBy(): array {
85        return $this->orders;
86    }
87
88    public function setLimit(int $offset, int $max): void {
89        $this->offset = $offset;
90        $this->max = $max;
91    }
92
93    public function offset(): int {
94        return $this->offset;
95    }
96
97    public function max(): int {
98        return $this->max;
99    }
100
101}