Completed
Push — master ( d0e52c...4fbece )
by Dmitry
45:12 queued 05:11
created

ColumnSchema   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dbTypecast() 0 12 3
A phpTypecast() 0 12 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
    public function dbTypecast($value)
25
    {
26
        if ($value instanceof ExpressionInterface) {
27
            return $value;
28
        }
29
30
        if ($this->dbType === Schema::TYPE_JSON) {
31
            return new JsonExpression($value, $this->type);
32
        }
33
34
        return $this->typecast($value);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function phpTypecast($value)
41
    {
42
        if ($value === null) {
43
            return null;
44
        }
45
46
        if ($this->type === Schema::TYPE_JSON) {
47
            return json_decode($value, true);
48
        }
49
50
        return parent::phpTypecast($value);
51
    }
52
}
53