Completed
Branch feature/pre-split (ce4b6b)
by Anton
03:56
created

ForeignsTrait::createForeign()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 5
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\ORM\Schemas\Relations\Traits;
8
9
use Spiral\Database\Schemas\Prototypes\AbstractColumn;
10
use Spiral\Database\Schemas\Prototypes\AbstractTable;
11
12
/**
13
 * Simplified functionality to create foreign for a given schema.
14
 */
15
trait ForeignsTrait
16
{
17
    /**
18
     * @param AbstractTable  $table
19
     * @param AbstractColumn $source
20
     * @param AbstractColumn $target
21
     * @param string         $onDelete
22
     * @param string         $onUpdate
23
     */
24
    protected function createForeign(
25
        AbstractTable $table,
26
        AbstractColumn $source,
27
        AbstractColumn $target,
28
        string $onDelete,
29
        string $onUpdate
30
    ) {
31
        $foreignKey = $table->foreign($source->getName())->references(
32
            $target->getTable(),
33
            $target->getName(),
34
            false
35
        );
36
37
        $foreignKey->onDelete($onDelete);
38
        $foreignKey->onUpdate($onUpdate);
39
    }
40
}