Completed
Push — master ( 467d47...6f2bb4 )
by Anton
14s
created

TableRelations::linkToMany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 4
ccs 0
cts 3
cp 0
c 0
b 0
f 0
cc 1
eloc 2
nop 2
crap 2
rs 10
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Db\Traits;
12
13
use Bluz\Db\Relations;
14
15
/**
16
 * TableRelations
17
 *
18
 * @package  Bluz\Db\Traits
19
 * @author   Anton Shevchuk
20
 */
21
trait TableRelations
22
{
23
    /**
24
     * Setup relation "one to one" or "one to many"
25
     *
26
     * @param  string $key
27
     * @param  string $model
28
     * @param  string $foreign
29
     *
30
     * @return void
31
     */
32
    public function linkTo($key, $model, $foreign) : void
33
    {
34
        Relations::setRelation($this->model, $key, $model, $foreign);
0 ignored issues
show
Bug introduced by
The property model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
    }
36
37
    /**
38
     * Setup relation "many to many"
39
     * [table1-key] [table1_key-table2-table3_key] [table3-key]
40
     *
41
     * @param  string $model
42
     * @param  string $link
43
     *
44
     * @return void
45
     */
46
    public function linkToMany($model, $link) : void
47
    {
48
        Relations::setRelations($this->model, $model, [$link]);
49
    }
50
}
51