RelationsBlock   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 23
c 1
b 0
f 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A wrapItem() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Renderer\PhpFileRenderer\Item;
6
7
use Cycle\ORM\Relation;
8
use Cycle\Schema\Renderer\PhpFileRenderer\Exporter\ArrayBlock;
9
use Cycle\Schema\Renderer\PhpFileRenderer\Exporter\ArrayItem;
10
11
class RelationsBlock extends ArrayBlock
12
{
13
    private const OPTION_KEYS = [
14
        Relation::TYPE => 'Relation::TYPE',
15
        Relation::TARGET => 'Relation::TARGET',
16
        Relation::SCHEMA => 'Relation::SCHEMA',
17
        Relation::LOAD => 'Relation::LOAD',
18
    ];
19
20
    private const OPTION_VALUES = [
21
        Relation::LOAD => [
22
            Relation::LOAD_PROMISE => 'Relation::LOAD_PROMISE',
23
            Relation::LOAD_EAGER => 'Relation::LOAD_EAGER',
24
        ],
25
        Relation::TYPE => [
26
            Relation::HAS_ONE => 'Relation::HAS_ONE',
27
            Relation::HAS_MANY => 'Relation::HAS_MANY',
28
            Relation::BELONGS_TO => 'Relation::BELONGS_TO',
29
            Relation::REFERS_TO => 'Relation::REFERS_TO',
30
            Relation::MANY_TO_MANY => 'Relation::MANY_TO_MANY',
31
            Relation::BELONGS_TO_MORPHED => 'Relation::BELONGS_TO_MORPHED',
32
            Relation::MORPHED_HAS_ONE => 'Relation::MORPHED_HAS_ONE',
33
            Relation::MORPHED_HAS_MANY => 'Relation::MORPHED_HAS_MANY',
34
        ],
35
    ];
36
37
    /**
38
     * @param int|string $key
39
     * @param mixed $value
40
     */
41
    protected function wrapItem($key, $value): ArrayItem
42
    {
43
        $item = parent::wrapItem($key, $value);
44
        if (is_array($value)) {
45
            $item->setValue(new RelationBlock($value, self::OPTION_KEYS, self::OPTION_VALUES), false);
46
        }
47
        return $item;
48
    }
49
}
50