Column::buildUnsignedString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle;
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 Oracle Server.
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 14
    protected function buildUnsignedString(): string
32
    {
33 14
        return $this->isUnsigned() ? ' UNSIGNED' : '';
34
    }
35
36
    /**
37
     * Builds the full string for the column's schema.
38
     */
39 14
    public function asString(): string
40
    {
41 14
        $format = match ($this->getTypeCategory()) {
42 14
            self::TYPE_CATEGORY_PK => '{type}{length}{check}{append}',
43 14
            self::TYPE_CATEGORY_NUMERIC => '{type}{length}{unsigned}{default}{notnull}{check}{append}',
44 14
            self::TYPE_CATEGORY_UUID => '{type}{notnull}{unique}{default}{check}{comment}{append}',
45 14
            self::TYPE_CATEGORY_UUID_PK => '{type}{notnull}{check}{comment}{append}',
46 14
            default => '{type}{length}{default}{notnull}{check}{append}',
47 14
        };
48
49 14
        return $this->buildCompleteString($format);
50
    }
51
}
52