Completed
Push — master ( f1a1d9...18cd95 )
by Paweł
30s queued 17s
created

ColumnSchemaBuilder::getDefaultValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 1
b 0
f 0
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\mssql;
9
10
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
11
use yii\db\Expression;
12
13
/**
14
 * ColumnSchemaBuilder is the schema builder for MSSQL databases.
15
 *
16
 * @author Valerii Gorbachev <[email protected]>
17
 * @since 2.0.42
18
 */
19
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
20
{
21
    protected $format = '{type}{length}{notnull}{unique}{default}{check}{append}';
22
23
    /**
24
     * Builds the full string for the column's schema.
25
     * @return string
26
     */
27
    public function __toString()
28
    {
29
        if ($this->getTypeCategory() === self::CATEGORY_PK) {
30
            $format = '{type}{check}{comment}{append}';
31
        } else {
32
            $format = $this->format;
33
        }
34
35
        return $this->buildCompleteString($format);
36
    }
37
38
    /**
39
     * Changes default format string to MSSQL ALTER COMMAND
40
     */
41
    public function setAlterColumnFormat()
42
    {
43
        $this->format = '{type}{length}{notnull}{append}';
44
    }
45
46
    /**
47
     * Getting the `Default` value for constraint
48
     * @return string|Expression|null
49
     */
50
    public function getDefaultValue()
51
    {
52
        if ($this->default instanceof Expression) {
53
            return $this->default;
54
        }
55
56
        return $this->buildDefaultValue();
57
    }
58
59
    /**
60
     * Get the `Check` value for constraint
61
     * @return string|null
62
     */
63
    public function getCheckValue()
64
    {
65
        return $this->check !== null ? (string) $this->check : null;
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isUnique()
72
    {
73
        return $this->isUnique;
74
    }
75
}
76