| Total Complexity | 10 |
| Total Lines | 98 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | trait AggregateTrait |
||
| 13 | { |
||
| 14 | |||
| 15 | use AbstractTrait; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * `AVG($this)` |
||
| 19 | * |
||
| 20 | * @return Num |
||
| 21 | */ |
||
| 22 | public function avg() |
||
| 23 | { |
||
| 24 | return Num::factory($this->db, "AVG({$this})"); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * `AVG(DISTINCT $this)` |
||
| 29 | * |
||
| 30 | * @return Num |
||
| 31 | */ |
||
| 32 | public function avgDistinct() |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * `COUNT($this)` |
||
| 39 | * |
||
| 40 | * @return Num |
||
| 41 | */ |
||
| 42 | public function count() |
||
| 43 | { |
||
| 44 | return Num::factory($this->db, "COUNT({$this})"); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * `COUNT(DISTINCT $this)` |
||
| 49 | * |
||
| 50 | * @return Num |
||
| 51 | */ |
||
| 52 | public function countDistinct() |
||
| 53 | { |
||
| 54 | return Num::factory($this->db, "COUNT(DISTINCT {$this})"); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * `GROUP_CONCAT($this)` using a delimiter. |
||
| 59 | * |
||
| 60 | * @param string $delimiter |
||
| 61 | * @return Str |
||
| 62 | */ |
||
| 63 | public function groupConcat(string $delimiter = ',') |
||
| 64 | { |
||
| 65 | $delimiter = $this->db->quote($delimiter); |
||
| 66 | if ($this->db->isSQLite()) { |
||
| 67 | return Str::factory($this->db, "GROUP_CONCAT({$this},{$delimiter})"); |
||
| 68 | } |
||
| 69 | return Str::factory($this->db, "GROUP_CONCAT({$this} SEPARATOR {$delimiter})"); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * `MAX($this)` |
||
| 74 | * |
||
| 75 | * @return Num |
||
| 76 | */ |
||
| 77 | public function max() |
||
| 78 | { |
||
| 79 | return Num::factory($this->db, "MAX({$this})"); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * `MIN($this)` |
||
| 84 | * |
||
| 85 | * @return Num |
||
| 86 | */ |
||
| 87 | public function min() |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * `SUM($this)` |
||
| 94 | * |
||
| 95 | * @return Num |
||
| 96 | */ |
||
| 97 | public function sum() |
||
| 98 | { |
||
| 99 | return Num::factory($this->db, "SUM({$this})"); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * `SUM(DISTINCT $this)` |
||
| 104 | * |
||
| 105 | * @return Num |
||
| 106 | */ |
||
| 107 | public function sumDistinct() |
||
| 110 | } |
||
| 111 | } |
||
| 112 |