Passed
Push — master ( 578537...871390 )
by Anton
08:44 queued 02:16
created

RenderRelations::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
namespace Cycle\Schema\Generator;
11
12
use Cycle\Schema\Definition\Entity;
13
use Cycle\Schema\GeneratorInterface;
14
use Cycle\Schema\Registry;
15
16
/**
17
 * Renders all required relations columns, indexes and foreign keys.
18
 */
19
final class RenderRelations implements GeneratorInterface
20
{
21
    /**
22
     * @param Registry $registry
23
     * @return Registry
24
     */
25
    public function run(Registry $registry): Registry
26
    {
27
        foreach ($registry as $entity) {
28
            $this->compute($registry, $entity);
29
        }
30
31
        return $registry;
32
    }
33
34
    /**
35
     * @param Registry $registry
36
     * @param Entity   $entity
37
     */
38
    protected function compute(Registry $registry, Entity $entity)
39
    {
40
        foreach ($registry->getRelations($entity) as $relation) {
41
            $relation->render($registry);
42
        }
43
    }
44
}