IndexConstraint::primary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Constraint;
6
7
/**
8
 * Represents an index constraint in a database.
9
 *
10
 * An index constraint is a constraint that enforces uniqueness or non-uniqueness of a column or a set of columns.
11
 *
12
 * It has information about the table and column(s) that the constraint applies to, as well as whether the index is
13
 * unique.
14
 */
15 94
final class IndexConstraint extends Constraint
16
{
17 94
    private bool $isUnique = false;
18
    private bool $isPrimary = false;
19
20
    /**
21
     * @return bool Whether the index is unique.
22
     */
23
    public function isUnique(): bool
24
    {
25
        return $this->isUnique;
26
    }
27
28
    /**
29
     * @return bool Whether the index was created for a primary key.
30 147
     */
31
    public function isPrimary(): bool
32 147
    {
33
        return $this->isPrimary;
34 147
    }
35
36
    /**
37
     * Set whether the index is unique.
38
     *
39
     * @param bool $value Whether the index is unique.
40
     */
41
    public function unique(bool $value): self
42 147
    {
43
        $this->isUnique = $value;
44 147
        return $this;
45
    }
46 147
47
    /**
48
     * Set whether the index was created for a primary key.
49
     *
50
     * @param bool $value whether the index was created for a primary key.
51
     */
52
    public function primary(bool $value): self
53
    {
54
        $this->isPrimary = $value;
55
        return $this;
56
    }
57
}
58