Passed
Push — master ( c6a312...8ed35d )
by y
05:46
created

NumTrait::asin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Helix\DB\SQL;
4
5
/**
6
 * Produces numeric expressions for the instance.
7
 */
8
trait NumTrait {
9
10
    use AbstractTrait;
11
12
    /**
13
     * `ABS($this)`
14
     *
15
     * @return Num
16
     */
17
    public function abs () {
18
        return Num::factory($this->db, "ABS({$this})");
19
    }
20
21
    /**
22
     * `ACOS($this)`
23
     *
24
     * @return Num
25
     */
26
    public function acos () {
27
        return Num::factory($this->db, "ACOS({$this})");
28
    }
29
30
    /**
31
     * `($this + $arg)`
32
     *
33
     * @param number|ValueInterface $arg
34
     * @return Num
35
     */
36
    public function add ($arg) {
37
        $arg = $this->db->quote($arg);
38
        return Num::factory($this->db, "({$this} + {$arg})");
39
    }
40
41
    /**
42
     * `ASIN($this)`
43
     *
44
     * @return Num
45
     */
46
    public function asin () {
47
        return Num::factory($this->db, "ASIN({$this})");
48
    }
49
50
    /**
51
     * `ATAN($this)`
52
     *
53
     * @return Num
54
     */
55
    public function atan () {
56
        return Num::factory($this->db, "ATAN({$this})");
57
    }
58
59
    /**
60
     * `CEIL($this)`
61
     *
62
     * @return Num
63
     */
64
    public function ceil () {
65
        return Num::factory($this->db, "CEIL({$this})");
66
    }
67
68
    /**
69
     * `COS($this)`
70
     *
71
     * @return Num
72
     */
73
    public function cos () {
74
        return Num::factory($this->db, "COS({$this})");
75
    }
76
77
    /**
78
     * Radians to degrees.
79
     *
80
     * `DEGREES($this)`
81
     *
82
     * @return Num
83
     */
84
    public function degrees () {
85
        return Num::factory($this->db, "DEGREES({$this})");
86
    }
87
88
    /**
89
     * `($this / $arg)`
90
     *
91
     * @param number|ValueInterface $arg
92
     * @return Num
93
     */
94
    public function div ($arg) {
95
        $arg = $this->db->quote($arg);
96
        return Num::factory($this->db, "({$this} / {$arg})");
97
    }
98
99
    /**
100
     * Euler's constant raised to the power of the expression.
101
     *
102
     * `EXP($this)`
103
     *
104
     * @return Num
105
     */
106
    public function exp () {
107
        return Num::factory($this->db, "EXP({$this})");
108
    }
109
110
    /**
111
     * `FLOOR($this)`
112
     *
113
     * @return Num
114
     */
115
    public function floor () {
116
        return Num::factory($this->db, "FLOOR({$this})");
117
    }
118
119
    /**
120
     * `($this % 2) = 0`
121
     *
122
     * @return Predicate
123
     */
124
    public function isEven () {
125
        return Predicate::factory($this->db, "({$this} % 2) = 0");
126
    }
127
128
    /**
129
     * `$this < 0`
130
     *
131
     * @return Predicate
132
     */
133
    public function isNegative () {
134
        return Predicate::factory($this->db, "{$this} < 0");
135
    }
136
137
    /**
138
     * `($this % 2) <> 0`
139
     *
140
     * @return Predicate
141
     */
142
    public function isOdd () {
143
        return Predicate::factory($this->db, "({$this} % 2) <> 0");
144
    }
145
146
    /**
147
     * `$this > 0`
148
     *
149
     * @return Predicate
150
     */
151
    public function isPositive () {
152
        return Predicate::factory($this->db, "{$this} > 0");
153
    }
154
155
    /**
156
     * `LN($this)`
157
     *
158
     * @return Num
159
     */
160
    public function ln () {
161
        return Num::factory($this->db, "LN({$this})");
162
    }
163
164
    /**
165
     * `LOG($base,$this)`
166
     *
167
     * > Note: This is the cross-DBMS signature. PHP's built-in function has the reverse.
168
     *
169
     * @param float $base
170
     * @return Num
171
     */
172
    public function log (float $base) {
173
        return Num::factory($this->db, "LOG({$base},{$this})");
174
    }
175
176
    /**
177
     * `LOG10($this)`
178
     *
179
     * @return Num
180
     */
181
    public function log10 () {
182
        return Num::factory($this->db, "LOG10({$this})");
183
    }
184
185
    /**
186
     * `LOG2($this)`
187
     *
188
     * @return Num
189
     */
190
    public function log2 () {
191
        return Num::factory($this->db, "LOG2({$this})");
192
    }
193
194
    /**
195
     * `($this % $divisor)`
196
     *
197
     * @param float $divisor
198
     * @return Num
199
     */
200
    public function mod (float $divisor) {
201
        return Num::factory($this->db, "({$this} % {$divisor})");
202
    }
203
204
    /**
205
     * `($this * $arg)`
206
     *
207
     * @param number|ValueInterface $arg
208
     * @return Num
209
     */
210
    public function mul ($arg) {
211
        $arg = $this->db->quote($arg);
212
        return Num::factory($this->db, "({$this} * {$arg})");
213
    }
214
215
    /**
216
     * `POW($this,$exponent)`
217
     *
218
     * @param float $exponent
219
     * @return Num
220
     */
221
    public function pow (float $exponent) {
222
        return Num::factory($this->db, "POW({$this},{$exponent})");
223
    }
224
225
    /**
226
     * Degrees to radians.
227
     *
228
     * `RADIANS($this)`
229
     *
230
     * @return Num
231
     */
232
    public function radians () {
233
        return Num::factory($this->db, "RADIANS({$this})");
234
    }
235
236
    /**
237
     * `ROUND($this,$decimals)`
238
     *
239
     * @param int $decimals
240
     * @return Num
241
     */
242
    public function round (int $decimals = 0) {
243
        return Num::factory($this->db, "ROUND({$this},{$decimals})");
244
    }
245
246
    /**
247
     * `SIGN($this)`
248
     *
249
     * @return Num `-1`, `0`, `1`
250
     */
251
    public function sign () {
252
        return Num::factory($this->db, "SIGN({$this})");
253
    }
254
255
    /**
256
     * `SIN($this)`
257
     *
258
     * @return Num
259
     */
260
    public function sin () {
261
        return Num::factory($this->db, "SIN({$this})");
262
    }
263
264
    /**
265
     * `SQRT($this)`
266
     *
267
     * @return Num
268
     */
269
    public function sqrt () {
270
        return Num::factory($this->db, "SQRT({$this})");
271
    }
272
273
    /**
274
     * `($this - $arg)`
275
     *
276
     * @param number|ValueInterface $arg
277
     * @return Num
278
     */
279
    public function sub ($arg) {
280
        $arg = $this->db->quote($arg);
281
        return Num::factory($this->db, "({$this} - {$arg})");
282
    }
283
284
    /**
285
     * `TAN($this)`
286
     *
287
     * @return Num
288
     */
289
    public function tan () {
290
        return Num::factory($this->db, "TAN({$this})");
291
    }
292
}