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

NumCastTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 26
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toInt() 0 5 2
A toFloat() 0 5 2
1
<?php
2
3
namespace Helix\DB\Fluent\Num;
4
5
use Helix\DB\Fluent\AbstractTrait;
6
use Helix\DB\Fluent\Num;
7
8
trait NumCastTrait {
9
10
    use AbstractTrait;
11
12
    /**
13
     * Casts the expression as a floating point number.
14
     *
15
     * @return Num
16
     */
17
    public function toFloat () {
18
        if ($this->db->isSQLite()) {
19
            return Num::factory($this->db, "CAST({$this} AS REAL)");
20
        }
21
        return Num::factory($this->db, "({$this} + 0)");
22
    }
23
24
    /**
25
     * Casts the expression as a signed integer.
26
     *
27
     * @return Num
28
     */
29
    public function toInt () {
30
        if ($this->db->isSQLite()) {
31
            return Num::factory($this->db, "CAST({$this} AS INTEGER)");
32
        }
33
        return Num::factory($this->db, "CAST({$this} AS SIGNED)");
34
    }
35
}
36