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

MutationConfigObject::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.8666
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace Softonic\GraphQL\Config;
4
5
use Softonic\GraphQL\Traits\JsonPathAccessor;
6
7
class MutationConfigObject
8
{
9
    use JsonPathAccessor;
10
11
    public $type;
12
13
    public $linksTo;
14
15
    public $children = [];
16
17 50
    public function __construct(array $config = [])
18
    {
19 50
        foreach ($config as $key => $value) {
20 50
            if ($key === 'children') {
21 50
                foreach ($value as $propertyName => $property) {
22 50
                    $this->children[$propertyName] = new static($property);
23
                }
24
            } else {
25 50
                $this->{$key} = $value;
26
            }
27
        }
28 50
    }
29
30
    public function __get($key)
31
    {
32
        if (property_exists(static::class, $key)) {
33
            return $this->{$key};
34
        }
35
36
        return $this->children[$key];
37
    }
38
}
39