Passed
Push — fix-php-docs ( 5267e5...e79c6c )
by Wilmer
12:35 queued 06:39
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
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 1
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 6
    protected function buildUnsignedString(): string
32
    {
33 6
        return $this->isUnsigned() ? ' UNSIGNED' : '';
34
    }
35
36
    /**
37
     * Builds the full string for the column's schema.
38
     */
39 6
    public function asString(): string
40
    {
41 6
        $format = match ($this->getTypeCategory()) {
42 6
            self::CATEGORY_PK => '{type}{length}{check}{append}',
43 6
            self::CATEGORY_NUMERIC => '{type}{length}{unsigned}{default}{notnull}{check}{append}',
44 6
            default => '{type}{length}{default}{notnull}{check}{append}',
45 6
        };
46
47 6
        return $this->buildCompleteString($format);
48
    }
49
}
50