Passed
Push — master ( 1f0d9b...6a4b0f )
by Wilmer
12:11 queued 10:38
created

ColumnSchema::phpTypecast()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql\Schema;
6
7
use Yiisoft\Db\Expression\ExpressionInterface;
8
use Yiisoft\Db\Expression\JsonExpression;
9
use Yiisoft\Db\Schema\ColumnSchema as AbstractColumnSchema;
10
11
/**
12
 * Class ColumnSchema for MySQL database.
13
 */
14
class ColumnSchema extends AbstractColumnSchema
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 44
    public function dbTypecast($value)
20
    {
21 44
        if ($value === null) {
22 5
            return $value;
23
        }
24
25 44
        if ($value instanceof ExpressionInterface) {
26 6
            return $value;
27
        }
28
29 42
        if ($this->getDbType() === Schema::TYPE_JSON) {
30
            return new JsonExpression($value, $this->getType());
31
        }
32
33 42
        return $this->typecast($value);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 80
    public function phpTypecast($value)
40
    {
41 80
        if ($value === null) {
42 79
            return;
43
        }
44
45 61
        if ($this->getType() === Schema::TYPE_JSON) {
46
            return \json_decode($value, true);
47
        }
48
49 61
        return parent::phpTypecast($value);
50
    }
51
}
52