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