Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Query | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| str | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | class Query |
| 4 | { |
| 5 | public function __construct($query) |
| 6 | { |
| 7 | $this->query = $query; |
| 8 | } |
| 9 | |
| 10 | public function str() |
| 11 | { |
| 12 | $result = $this->prefix; |
| 13 | $result .= 'SELECT '; |
| 14 | $result .= implode(', ', $this->selects); |
| 15 | $result .= ' '; |
| 16 | $result .= $this->query; |
| 17 | |
| 18 | if (!empty($this->conditions)) |
| 19 | $result .= ' WHERE ' . implode(' AND ', array_map(fn($c) => stripos($c, ' OR ') !== false ? "($c)" : $c, $this->conditions)); |
| 20 | if (!empty($this->groupBy)) |
| 21 | $result .= ' GROUP BY ' . implode(', ', $this->groupBy); |
| 22 | if (!empty($this->orderBy)) |
| 23 | $result .= ' ORDER BY ' . implode(', ', $this->orderBy); |
| 24 | $result .= $this->suffix; |
| 25 | return $result; |
| 26 | } |
| 27 | |
| 28 | public $selects = []; |
| 29 | public $query = ''; |
| 30 | public $conditions = []; |
| 31 | public $orderBy = []; |
| 32 | public $groupBy = []; |
| 33 | public $prefix; |
| 34 | public $suffix; |
| 35 | } |