Completed
Pull Request — master (#29)
by
unknown
01:32
created

MutationConfigBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
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 39
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
    const CHILDREN_PROPERTY_NAME = 'children';
8
9 74
    public function build(array $config): array
10
    {
11 74
        $mutationConfig = [];
12 74
        foreach ($config as $variable => $typeConfig) {
13 74
            $mutationConfig[$variable] = $this->buildMutationTypeConfig($typeConfig);
14
        }
15
16 74
        return $mutationConfig;
17
    }
18
19 74
    private function buildMutationTypeConfig(array $typeConfig): MutationTypeConfig
20
    {
21 74
        $mutationTypeConfig = new MutationTypeConfig();
22
23 74
        foreach ($typeConfig as $propertyName => $propertyValue) {
24 74
            $this->setMutationTypeConfig($mutationTypeConfig, $propertyName, $propertyValue);
25
        }
26
27 74
        return $mutationTypeConfig;
28
    }
29
30 74
    private function setMutationTypeConfig(
31
        MutationTypeConfig $mutationTypeConfig,
32
        string $propertyName,
33
        $propertyValue
34
    ): void {
35 74
        if ($propertyName === self::CHILDREN_PROPERTY_NAME) {
36 74
            foreach ($propertyValue as $childName => $childConfig) {
37 74
                $mutationTypeConfig->children[$childName] = $this->buildMutationTypeConfig($childConfig);
38
            }
39
        } else {
40 74
            $mutationTypeConfig->{$propertyName} = $propertyValue;
41
        }
42 74
    }
43
}
44