Passed
Push — master ( add693...b324e9 )
by Wilmer
13:51
created

MssqlColumnSchema::defaultPhpTypecast()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql\Schema;
6
7
use Yiisoft\Db\Schema\ColumnSchema;
8
9
use function substr;
10
11
/**
12
 * Class ColumnSchema for MSSQL database
13
 */
14
final class MssqlColumnSchema extends ColumnSchema
15
{
16
    /**
17
     * Prepares default value and converts it according to {@see phpType}.
18
     *
19
     * @param mixed $value default value
20
     *
21
     * @return mixed converted value
22
     */
23
    public function defaultPhpTypecast($value)
24
    {
25
        if ($value !== null) {
26
            // convert from MSSQL column_default format, e.g. ('1') -> 1, ('string') -> string
27
            $value = substr(substr($value, 2), 0, -2);
28
        }
29
30
        return $this->phpTypecast($value);
31
    }
32
}
33