Passed
Pull Request — master (#190)
by Def
06:04
created

Column::buildUnsignedString()   A

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 `\Yiisoft\Db\Oracle\Schema`}
11
 * for Oracle.
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
    /**
38
     * Builds the full string for the column's schema.
39
     *
40
     * @return string
41
     */
42 6
    public function asString(): string
43
    {
44 6
        $format = match ($this->getTypeCategory()) {
45 6
            self::CATEGORY_PK => '{type}{length}{check}{append}',
46 6
            self::CATEGORY_NUMERIC => '{type}{length}{unsigned}{default}{notnull}{check}{append}',
47 6
            default => '{type}{length}{default}{notnull}{check}{append}',
48 6
        };
49
50 6
        return $this->buildCompleteString($format);
51
    }
52
}
53