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

MutationConfigBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 37
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 9 2
A buildMutationTypeConfig() 0 10 2
A setMutationTypeConfig() 0 13 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