Passed
Push — master ( 1f0d9b...6a4b0f )
by Wilmer
12:11 queued 10:38
created

TableSchema::foreignKey()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql\Schema;
6
7
use Yiisoft\Db\Schema\TableSchema as AbstractTableSchema;
8
9
/**
10
 * TableSchema represents the metadata of a database table.
11
 *
12
 * @property array $columnNames List of column names. This property is read-only.
13
 */
14
class TableSchema extends AbstractTableSchema
15
{
16
    private array $foreignKeys = [];
17
18
    /**
19
     * @return array foreign keys of this table. Each array element is of the following structure:
20
     *
21
     * ```php
22
     * [
23
     *  'ForeignTableName',
24
     *  'fk1' => 'pk1',  // pk1 is in foreign table
25
     *  'fk2' => 'pk2',  // if composite foreign key
26
     * ]
27
     * ```
28
     */
29 2
    public function getForeignKeys(): array
30
    {
31 2
        return $this->foreignKeys;
32
    }
33
34 27
    public function foreignKey(string $id, array $to): void
35
    {
36 27
        $this->foreignKeys[$id] = $to;
37 27
    }
38
39 84
    public function foreignKeys(array $value): void
40
    {
41 84
        $this->foreignKeys = $value;
42 84
    }
43
}
44