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