Passed
Pull Request — 2.x (#67)
by Maxim
12:27
created

ForeignKeys::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Generator;
6
7
use Cycle\Schema\GeneratorInterface;
8
use Cycle\Schema\Registry;
9
10
final class ForeignKeys implements GeneratorInterface
11
{
12
    public function run(Registry $registry): Registry
13
    {
14
        foreach ($registry as $entity) {
15
            foreach ($entity->getForeignKeys() as $fk) {
16
                $registry->getTableSchema($entity)
17
                    ->foreignKey($fk->getInnerColumns(), $fk->isCreateIndex())
18
                    ->references($fk->getTable(), $fk->getOuterColumns())
19
                    ->onUpdate($fk->getAction())
20
                    ->onDelete($fk->getAction());
21
            }
22
        }
23
24
        return $registry;
25
    }
26
}
27