Passed
Push — master ( a5f56c...d0ba85 )
by y
01:34
created

Text::toFloat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Helix\DB\SQL;
4
5
/**
6
 * Represents a text expression. Produces various transformations.
7
 */
8
class Text extends Scalar {
9
10
    use TextTrait;
11
12
    /**
13
     * Casts the expression to a floating point number.
14
     *
15
     * @return Numeric
16
     */
17
    public function toFloat () {
18
        if ($this->db->getDriver() === 'sqlite') {
19
            return new Numeric($this->db, "CAST({$this} AS REAL)");
20
        }
21
        return new Numeric($this->db, "({$this} + 0)");
22
    }
23
24
    /**
25
     * Casts the expression to a signed integer.
26
     *
27
     * @return Numeric
28
     */
29
    public function toInt () {
30
        if ($this->db->getDriver() === 'sqlite') {
31
            return new Numeric($this->db, "CAST({$this} AS INTEGER)");
32
        }
33
        return new Numeric($this->db, "CAST({$this} AS SIGNED)");
34
    }
35
}