Passed
Push — master ( 222f48...0fa176 )
by y
01:47
created

NumTrait::asin()   A

Complexity

Conditions 1
Paths 1

Size

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