Passed
Push — master ( c85748...2fd0ab )
by Petr
08:11
created

TForeignKey   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getForeignKeys() 0 3 1
A initClassFks() 0 4 2
A addForeignKey() 0 5 1
1
<?php
2
3
namespace kalanis\kw_mapper\Mappers\Shared;
4
5
6
/**
7
 * Trait TForeignKey
8
 * @package kalanis\kw_mapper\Mappers\Shared
9
 * Accessing foreign keys
10
 *
11
 * @todo idea: fk from/to composite keys
12
 *     - shall be like array where the first entry is what will join and then what entry aliases will be used
13
 */
14
trait TForeignKey
15
{
16
    /** @var array<string, ForeignKey> */
17
    protected $foreignKeys = [];
18
    /** @var ForeignKey|null */
19
    private $foreignKeyClass = null;
20
21 7
    public function addForeignKey(string $localAlias, string $remoteRecord, string $localEntryKey, string $remoteEntryKey): void
22
    {
23 7
        $this->initClassFks();
24 7
        $foreignKeyClass = clone $this->foreignKeyClass;
25 7
        $this->foreignKeys[$localAlias] = $foreignKeyClass->setData($localAlias, $remoteRecord, $localEntryKey, $remoteEntryKey);
26
    }
27
28 7
    private function initClassFks(): void
29
    {
30 7
        if (empty($this->foreignKeyClass)) {
31 7
            $this->foreignKeyClass = new ForeignKey();
32
        }
33
    }
34
35
    /**
36
     * @return array<string, ForeignKey>
37
     */
38 11
    public function getForeignKeys(): array
39
    {
40 11
        return $this->foreignKeys;
41
    }
42
}
43