Completed
Push — master ( 07fa0a...a5b00e )
by Edgard
10:14
created

ColumnSchema   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 82.61%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 1
dl 0
loc 45
ccs 19
cts 23
cp 0.8261
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D typecast() 0 34 17
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace edgardmessias\db\firebird;
9
10
use yii\db\Expression;
11
12
/**
13
 *
14
 * @author Edgard Lorraine Messias <[email protected]>
15
 * @since 2.0
16
 */
17
class ColumnSchema extends \yii\db\ColumnSchema
18
{
19
20
    /**
21
     * Converts the input value according to [[phpType]] after retrieval from the database.
22
     * If the value is null or an [[Expression]], it will not be converted.
23
     * @param mixed $value input value
24
     * @return mixed converted value
25
     * @since 2.0.3
26
     */
27 89
    protected function typecast($value)
28
    {
29
30 89
        if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) {
31 1
            return null;
32
        }
33 89
        if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
34 85
            return $value;
35
        }
36
37 81
        switch ($this->phpType) {
38 81
            case 'resource':
39 81
            case 'string':
40 6
                if (is_resource($value)) {
41
                    return $value;
42
                }
43 6
                if (is_float($value)) {
44
                    // ensure type cast always has . as decimal separator in all locales
45 2
                    return str_replace(',', '.', (string) $value);
46
                }
47 4
                return (string) $value;
48 80
            case 'integer':
49 80
                if (is_bool($value)) {
50 2
                    return ($value) ? 1 : 0;
51
                }
52 80
                return (int) $value;
53 13
            case 'boolean':
54
                return (boolean) $value;
55 13
            case 'double':
56 13
                return (double) $value;
57
        }
58
59
        return $value;
60
    }
61
}
62