Passed
Push — master ( 565bd9...e00335 )
by Def
19:37 queued 15:49
created

Column::asString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite;
6
7
use Yiisoft\Db\Schema\Builder\AbstractColumn;
8
9
/**
10
 * It's a utility that provides a convenient way to create column schema for use with {@see `\Yiisoft\Db\SQLite\Schema`}
11
 * for SQLite.
12
 *
13
 * It provides methods for specifying the properties of a column, such as its type, size, default value, and whether it
14
 * is nullable or not. It also provides a method for creating a column schema based on the specified properties.
15
 *
16
 * For example, the following code creates a column schema for an integer column:
17
 *
18
 * ```php
19
 * $column = (new Column(SchemaInterface::TYPE_INTEGER))->notNull()->defaultValue(0);
20
 * ```
21
 *
22
 * Provides a fluent interface, which means that the methods can be chained together to create a column schema with
23
 * many properties in a single line of code.
24
 */
25
final class Column extends AbstractColumn
26
{
27
    /**
28
     * Builds the unsigned string for column. Defaults to unsupported.
29
     *
30
     * @return string a string containing UNSIGNED keyword.
31
     */
32 6
    protected function buildUnsignedString(): string
33
    {
34 6
        return $this->isUnsigned() ? ' UNSIGNED' : '';
35
    }
36
37 6
    public function asString(): string
38
    {
39 6
        $format = match ($this->getTypeCategory()) {
40 6
            self::CATEGORY_PK => '{type}{check}{append}',
41 6
            self::CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{unique}{check}{default}{append}',
42 6
            default => '{type}{length}{notnull}{unique}{check}{default}{append}',
43 6
        };
44
45 6
        return $this->buildCompleteString($format);
46
    }
47
}
48