TableRelations   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 5
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A linkToMany() 0 3 1
A linkTo() 0 3 1
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Db\Traits;
13
14
use Bluz\Db\Relations;
15
16
/**
17
 * TableRelations
18
 *
19
 * @package  Bluz\Db\Traits
20
 * @author   Anton Shevchuk
21
 */
22
trait TableRelations
23
{
24
    /**
25
     * Setup relation "one to one" or "one to many"
26
     *
27
     * @param  string $key
28
     * @param  string $model
29
     * @param  string $foreign
30
     *
31
     * @return void
32
     */
33
    public function linkTo($key, $model, $foreign): void
34
    {
35
        Relations::setRelation($this->model, $key, $model, $foreign);
36
    }
37
38
    /**
39
     * Setup relation "many to many"
40
     * [table1-key] [table1_key-table2-table3_key] [table3-key]
41
     *
42
     * @param  string $model
43
     * @param  string $link
44
     *
45
     * @return void
46
     */
47
    public function linkToMany($model, $link): void
48
    {
49
        Relations::setRelations($this->model, $model, [$link]);
50
    }
51
}
52