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

ForeignsTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

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