Test Failed
Pull Request — master (#264)
by Wilmer
04:14
created

Column::buildCompleteString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 17
ccs 0
cts 0
cp 0
crap 2
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use Yiisoft\Db\Expression\Expression;
8
use Yiisoft\Db\Schema\Builder\AbstractColumn;
9
10
/**
11
 * Provides a convenient way to create column schema for use with {@see Schema} for MSSQL Server.
12
 *
13
 * It has 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
    private bool $clustered = false;
28
29
    /**
30 8
     * @return Expression|string|null The default value of the column.
31
     */
32 8
    public function getDefault(): Expression|string|null
33 3
    {
34
        if ($this->default instanceof Expression) {
35
            return $this->default;
36 7
        }
37
38
        return $this->buildDefaultValue();
39
    }
40
41
    public function clustered(): self
42
    {
43
        $this->format = '{type}{length}{notnull}{primarykey}{unique}{default}{check}{comment}{append}{clustered}';
44
        $this->clustered = true;
45
        return $this;
46
    }
47
48
    public function isClustered(): self
49
    {
50
        $this->clustered = true;
51
        return $this;
52
    }
53
54
    /**
55
     * Returns the complete column definition from input format.
56
     *
57
     * @param string $format The format of the definition.
58
     *
59
     * @return string A string containing the complete column definition.
60
     */
61
    protected function buildCompleteString(string $format): string
62
    {
63
        $placeholderValues = [
64
            '{type}' => $this->type,
65
            '{length}' => $this->buildLengthString(),
66
            '{unsigned}' => $this->buildUnsignedString(),
67
            '{notnull}' => $this->buildNotNullString(),
68
            '{primarykey}' => $this->buildPrimaryKeyString(),
0 ignored issues
show
Bug introduced by
The method buildPrimaryKeyString() does not exist on Yiisoft\Db\Mssql\Column. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
            '{primarykey}' => $this->/** @scrutinizer ignore-call */ buildPrimaryKeyString(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
            '{unique}' => $this->buildUniqueString(),
70
            '{default}' => $this->buildDefaultString(),
71
            '{check}' => $this->buildCheckString(),
72
            '{comment}' => $this->buildCommentString(),
73
            '{append}' => $this->buildAppendString(),
74
            '{clustered}' => $this->buildClustered(),
75
        ];
76
77
        return strtr($format, $placeholderValues);
78
    }
79
80
    private function buildClustered(): string
81
    {
82
        return $this->clustered ? ' CLUSTERED' : '';
83
    }
84
}
85