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

MutationConfigBuilder::setMutationTypeConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
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