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

TableSchema   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 39
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A compositeFK() 0 3 1
A foreignKey() 0 3 1
A foreignKeys() 0 3 1
A getForeignKeys() 0 3 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