Passed
Push — 2.2 ( c9917f...37714b )
by Alexander
02:01 queued 17s
created

ColumnSchema::phpTypecast()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://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 for MySQL database
15
 *
16
 * @author Dmytro Naumenko <[email protected]>
17
 * @since 2.0.14.1
18
 */
19
class ColumnSchema extends \yii\db\ColumnSchema
20
{
21
    /**
22
     * @var bool whether the column schema should OMIT using JSON support feature.
23
     * You can use this property to make upgrade to Yii 2.0.14 easier.
24
     * Default to `false`, meaning JSON support is enabled.
25
     *
26
     * @since 2.0.14.1
27
     * @deprecated Since 2.0.14.1 and will be removed in 2.1.
28
     */
29
    public $disableJsonSupport = false;
30
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 5
    public function dbTypecast($value)
36
    {
37 5
        if ($value === null) {
38
            return $value;
39
        }
40
41 5
        if ($value instanceof ExpressionInterface) {
42
            return $value;
43
        }
44
45 5
        if (!$this->disableJsonSupport && $this->dbType === Schema::TYPE_JSON) {
0 ignored issues
show
Deprecated Code introduced by
The property yii\db\mysql\ColumnSchema::$disableJsonSupport has been deprecated: Since 2.0.14.1 and will be removed in 2.1. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

45
        if (!/** @scrutinizer ignore-deprecated */ $this->disableJsonSupport && $this->dbType === Schema::TYPE_JSON) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
46 5
            return new JsonExpression($value, $this->type);
47
        }
48
49
        return $this->typecast($value);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 5
    public function phpTypecast($value)
56
    {
57 5
        if ($value === null) {
58 5
            return null;
59
        }
60
61 5
        if (!$this->disableJsonSupport && $this->type === Schema::TYPE_JSON) {
0 ignored issues
show
Deprecated Code introduced by
The property yii\db\mysql\ColumnSchema::$disableJsonSupport has been deprecated: Since 2.0.14.1 and will be removed in 2.1. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

61
        if (!/** @scrutinizer ignore-deprecated */ $this->disableJsonSupport && $this->type === Schema::TYPE_JSON) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
62 5
            return json_decode($value, true);
63
        }
64
65 5
        return parent::phpTypecast($value);
66
    }
67
}
68