Passed
Branch dev (ea35c5)
by Wilmer
17:29 queued 12:43
created

TableSchema::compositeFK()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite;
6
7
use Yiisoft\Db\Schema\TableSchema as AbstractTableSchema;
8
9
final class TableSchema extends AbstractTableSchema
10
{
11
    /**
12
     * @psalm-var array<array-key, array>
13
     */
14
    private array $foreignKeys = [];
15
16
    /**
17
     * ```php
18
     * [
19
     *  'ForeignTableName',
20
     *  'fk1' => 'pk1',  // pk1 is in foreign table
21
     *  'fk2' => 'pk2',  // if composite foreign key
22
     * ]
23
     * ```
24
     *
25
     * @return array foreign keys of this table. Each array element is of the following structure:
26
     */
27 5
    public function getForeignKeys(): array
28
    {
29 5
        return $this->foreignKeys;
30
    }
31
32 5
    public function compositeFK(int $id, string $from, string $to): void
33
    {
34 5
        $this->foreignKeys[$id][$from] = $to;
35
    }
36
37 5
    public function foreignKey(int $id, array $to): void
38
    {
39 5
        $this->foreignKeys[$id] = $to;
40
    }
41
42
    /**
43
     * @psalm-param array<array-key, array> $value
44
     */
45
    public function foreignKeys(array $value): void
46
    {
47
        $this->foreignKeys = $value;
48
    }
49
}
50