GenerateModifiers   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 13 3
A run() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Generator;
6
7
use Cycle\Schema\Definition\Entity;
8
use Cycle\Schema\Exception\SchemaException;
9
use Cycle\Schema\Exception\SchemaModifierException;
10
use Cycle\Schema\GeneratorInterface;
11
use Cycle\Schema\Registry;
12
use Cycle\Schema\SchemaModifierInterface;
13
14
/**
15
 * Generate modifiers based on their schematic definitions.
16
 */
17
final class GenerateModifiers implements GeneratorInterface
18
{
19 6
    public function run(Registry $registry): Registry
20
    {
21 6
        foreach ($registry as $entity) {
22 6
            $this->register($registry, $entity);
23
        }
24
25 2
        return $registry;
26
    }
27
28 6
    protected function register(Registry $registry, Entity $entity): void
29
    {
30 6
        $role = $entity->getRole();
31
        assert($role !== null);
32 6
        foreach ($entity->getSchemaModifiers() as $modifier) {
33
            \assert($modifier instanceof SchemaModifierInterface);
34
            try {
35 6
                $modifier->compute($registry);
36 4
            } catch (SchemaModifierException $e) {
37 4
                throw new SchemaException(
38 4
                    sprintf('Unable to compute modifier `%s` for the `%s` role.', $modifier::class, $role),
39 4
                    $e->getCode(),
40
                    $e,
41
                );
42
            }
43
        }
44 2
    }
45
}
46