IndexConstraint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 41
ccs 8
cts 10
cp 0.8
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isPrimary() 0 3 1
A isUnique() 0 3 1
A unique() 0 4 1
A primary() 0 4 1
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