Column   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildUnsignedString() 0 3 2
A asString() 0 11 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 Schema} for SQLite.
11
 *
12
 * It provides methods for specifying the properties of a column, such as its type, size, default value, and whether it
13
 * is nullable or not. It also provides a method for creating a column schema based on the specified properties.
14
 *
15
 * For example, the following code creates a column schema for an integer column:
16
 *
17
 * ```php
18
 * $column = (new Column(SchemaInterface::TYPE_INTEGER))->notNull()->defaultValue(0);
19
 * ```
20
 *
21
 * Provides a fluent interface, which means that the methods can be chained together to create a column schema with
22
 * many properties in a single line of code.
23
 */
24
final class Column extends AbstractColumn
25
{
26
    /**
27
     * Builds the unsigned string for column. Defaults to unsupported.
28
     *
29
     * @return string a string containing UNSIGNED keyword.
30
     */
31 15
    protected function buildUnsignedString(): string
32
    {
33 15
        return $this->isUnsigned() ? ' UNSIGNED' : '';
34
    }
35
36 15
    public function asString(): string
37
    {
38 15
        $format = match ($this->getTypeCategory()) {
39 15
            self::TYPE_CATEGORY_PK => '{type}{check}{append}',
40 15
            self::TYPE_CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{unique}{check}{default}{append}',
41 15
            self::TYPE_CATEGORY_UUID => '{type}{notnull}{unique}{default}{check}{comment}{append}',
42 15
            self::TYPE_CATEGORY_UUID_PK => '{type}{notnull}{default}{check}{comment}{append}',
43 15
            default => '{type}{length}{notnull}{unique}{check}{default}{append}',
44 15
        };
45
46 15
        return $this->buildCompleteString($format);
47
    }
48
}
49