ForeignsTrait::createForeign()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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