Passed
Push — master ( cf86c2...f16abf )
by y
02:43
created

NumCastFloatTrait::toFloat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Helix\DB\Fluent\Num;
4
5
use Helix\DB\Fluent\AbstractTrait;
6
use Helix\DB\Fluent\Num;
7
8
/**
9
 * Further manipulate the expression as a float.
10
 */
11
trait NumCastFloatTrait
12
{
13
14
    use AbstractTrait;
15
16
    /**
17
     * Casts the expression as a floating point number.
18
     *
19
     * @return Num
20
     */
21
    public function toFloat()
22
    {
23
        if ($this->db->isSQLite()) {
24
            return Num::factory($this->db, "CAST({$this} AS REAL)");
25
        }
26
        return Num::factory($this->db, "({$this} + 0)");
27
    }
28
}
29