Test Failed
Pull Request — master (#259)
by Def
02:49
created

Column::buildUnsignedString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql;
6
7
use Exception;
8
use Yiisoft\Db\Schema\Builder\AbstractColumn;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Schema\Builder\AbstractColumn was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Yiisoft\Db\Schema\QuoterInterface;
10
11
/**
12
 * It's a utility that provides a convenient way to create column schema for use with {@see `\Yiisoft\Db\Mysql\Schema`}
13
 * for MySQL, MariaDb Server.
14
 *
15
 * It provides methods for specifying the properties of a column, such as its type, size, default value, and whether it
16
 * is nullable or not. It also provides a method for creating a column schema based on the specified properties.
17
 *
18
 * For example, the following code creates a column schema for an integer column:
19
 *
20
 * ```php
21
 * $column = (new Column(SchemaInterface::TYPE_INTEGER))->notNull()->defaultValue(0);
22
 * ```
23
 *
24
 * Provides a fluent interface, which means that the methods can be chained together to create a column schema with
25
 * many properties in a single line of code.
26
 */
27
final class Column extends AbstractColumn
28
{
29
    private QuoterInterface|null $quoter = null;
0 ignored issues
show
introduced by
The private property $quoter is not used, and could be removed.
Loading history...
30
31
    /**
32
     * Builds the unsigned string for column. Defaults to unsupported.
33
     *
34
     * @return string a string containing UNSIGNED keyword.
35
     */
36
    protected function buildUnsignedString(): string
37
    {
38
        return $this->isUnsigned() ? ' UNSIGNED' : '';
39
    }
40
41
    /**
42
     * Builds the comment specification for the column.
43
     *
44
     * @throws Exception
45
     *
46
     * @return string a string containing the COMMENT keyword and the comment itself.
47
     */
48
    protected function buildCommentString(): string
49
    {
50
        if ($this->getComment() === null) {
51
            return '';
52
        }
53
54
        return ' COMMENT ' . (new Quoter('`', '`'))->quoteValue($this->getComment());
55
    }
56
57
    public function asString(): string
58
    {
59
        $format = match ($this->getTypeCategory()) {
60
            self::CATEGORY_PK => '{type}{length}{comment}{check}{append}',
61
            self::CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{default}{unique}{comment}{append}{check}',
62
            default => '{type}{length}{notnull}{default}{unique}{comment}{append}{check}',
63
        };
64
65
        return $this->buildCompleteString($format);
66
    }
67
}
68