Completed
Push — master ( 1500e7...dc452b )
by Dmitry
63:45 queued 60:13
created

ColumnSchema::phpTypecast()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 2
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
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 yii\db\mysql;
9
10
use yii\db\ExpressionInterface;
11
use yii\db\JsonExpression;
12
13
/**
14
 * Class ColumnSchema
15
 *
16
 * @author Dmytro Naumenko <[email protected]>
17
 * @since 2.0.14.1
18
 */
19
class ColumnSchema extends \yii\db\ColumnSchema
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 210
    public function dbTypecast($value)
25
    {
26 210
        if ($value instanceof ExpressionInterface) {
27 24
            return $value;
28
        }
29
30 207
        if ($this->dbType === Schema::TYPE_JSON) {
31 1
            return new JsonExpression($value, $this->type);
32
        }
33
34 206
        return $this->typecast($value);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 328
    public function phpTypecast($value)
41
    {
42 328
        if ($value === null) {
43 326
            return null;
44
        }
45
46 176
        if ($this->type === Schema::TYPE_JSON) {
47 1
            return json_decode($value, true);
48
        }
49
50 176
        return parent::phpTypecast($value);
51
    }
52
}
53