Passed
Push — master ( ae25c0...fd0368 )
by Anton
01:32
created

OptionMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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\Relation;
11
12
use Cycle\Schema\Exception\OptionException;
13
14
final class OptionMapper
15
{
16
    /** @var array */
17
    private $map = [];
18
19
    /**
20
     * @param array $map
21
     */
22
    public function __construct(array $map)
23
    {
24
        $this->map = $map;
25
    }
26
27
    /**
28
     * @param iterable $options
29
     * @return array
30
     *
31
     * @throws OptionException
32
     */
33
    public function map(iterable $options): array
34
    {
35
        $result = [];
36
        foreach ($options as $name => $value) {
37
            if (!isset($this->map[$name])) {
38
                throw new OptionException("Undefined relation option `$name`");
39
            }
40
41
            $result[$this->map[$name]] = $value;
42
        }
43
44
        return $result;
45
    }
46
}