Passed
Pull Request — master (#22)
by Wilmer
15:13
created

ColumnSchemaBuilder::buildCommentString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
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\Schema\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
8
9
/**
10
 * ColumnSchemaBuilder is the schema builder for MySQL databases.
11
 */
12
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected function buildUnsignedString(): string
18
    {
19
        return $this->getIsUnsigned() ? ' UNSIGNED' : '';
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function buildAfterString(): string
26
    {
27
        return $this->getAfter() !== null ? ' AFTER ' . $this->getDb()->quoteColumnName($this->getAfter()) : '';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected function buildFirstString(): string
34
    {
35
        return $this->getIsFirst() ? ' FIRST' : '';
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function buildCommentString(): string
42
    {
43
        return $this->getComment() !== null ? ' COMMENT ' . $this->getDb()->quoteValue($this->getComment()) : '';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function __toString(): string
50
    {
51
        switch ($this->getTypeCategory()) {
52
            case self::CATEGORY_PK:
53
                $format = '{type}{length}{comment}{check}{append}{pos}';
54
                break;
55
            case self::CATEGORY_NUMERIC:
56
                $format = '{type}{length}{unsigned}{notnull}{default}{unique}{comment}{append}{pos}{check}';
57
                break;
58
            default:
59
                $format = '{type}{length}{notnull}{default}{unique}{comment}{append}{pos}{check}';
60
        }
61
62
        return $this->buildCompleteString($format);
63
    }
64
}
65