ForeignsTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createForeign() 0 16 1
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
}