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

RenderRelations   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 7 2
A compute() 0 4 2
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
}