Completed
Pull Request — master (#29)
by
unknown
06:10
created

MutationConfigBuilder::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Softonic\GraphQL\Config;
4
5
class MutationConfigBuilder
6
{
7 52
    public function build(array $config): array
8
    {
9 52
        $mutationConfig = [];
10 52
        foreach ($config as $variable => $typeConfig) {
11 52
            $mutationConfig[$variable] = $this->buildMutationTypeConfig($typeConfig);
12
        }
13
14 52
        return $mutationConfig;
15
    }
16
17 52
    private function buildMutationTypeConfig(array $typeConfig): MutationTypeConfig
18
    {
19 52
        $mutationTypeConfig = new MutationTypeConfig();
20
21 52
        foreach ($typeConfig as $propertyName => $propertyValue) {
22 52
            $this->setMutationTypeConfig($mutationTypeConfig, $propertyName, $propertyValue);
23
        }
24
25 52
        return $mutationTypeConfig;
26
    }
27
28 52
    private function setMutationTypeConfig(
29
        MutationTypeConfig $mutationTypeConfig,
30
        string $propertyName,
31
        $propertyValue
32
    ): void {
33 52
        if ($propertyName === 'children') {
34 52
            foreach ($propertyValue as $childName => $childConfig) {
35 52
                $mutationTypeConfig->children[$childName] = $this->buildMutationTypeConfig($childConfig);
36
            }
37
        } else {
38 52
            $mutationTypeConfig->{$propertyName} = $propertyValue;
39
        }
40 52
    }
41
}
42