AggregateTrait::max()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Helix\DB\Fluent\Value;
4
5
use Helix\DB\Fluent\AbstractTrait;
6
use Helix\DB\Fluent\Num;
7
use Helix\DB\Fluent\Str;
8
9
/**
10
 * Aggregation functions.
11
 */
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()
33
    {
34
        return Num::factory($this->db, "AVG(DISTINCT {$this})");
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()
88
    {
89
        return Num::factory($this->db, "MIN({$this})");
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()
108
    {
109
        return Num::factory($this->db, "SUM(DISTINCT {$this})");
110
    }
111
}
112