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

Item   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 46
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __get() 0 10 3
A __set() 0 6 1
A hasChanged() 0 10 4
1
<?php
2
3
namespace Softonic\GraphQL\Mutation;
4
5
use Softonic\GraphQL\Traits\JsonSerializer;
6
7
class Item implements MutationObject, \JsonSerializable
8
{
9
    use JsonSerializer;
10
11
    private $arguments;
12
13
    private $config;
14
15
    private $hasChanged = false;
16
17 48
    public function __construct(array $arguments = [], array $config = [], bool $hasChanged = false)
18
    {
19 48
        $this->arguments  = $arguments;
20 48
        $this->config     = $config;
21 48
        $this->hasChanged = $hasChanged;
22 48
    }
23
24 28
    public function __get(string $key)
25
    {
26 28
        if (is_null($this->arguments[$key]) && array_key_exists($key, $this->config)) {
27
            $mutationType = $this->config[$key]->type;
28
29
            $this->arguments[$key] = new $mutationType([], $this->config[$key]->children);
30
        }
31
32 28
        return $this->arguments[$key];
33
    }
34
35 26
    public function __set(string $key, $value)
36
    {
37 26
        $this->arguments[$key] = $value;
38
39 26
        $this->hasChanged = true;
40 26
    }
41
42 34
    public function hasChanged(): bool
43
    {
44 34
        foreach ($this->arguments as $argument) {
45 34
            if ($argument instanceof MutationObject && $argument->hasChanged()) {
46 26
                return true;
47
            }
48
        }
49
50 34
        return $this->hasChanged;
51
    }
52
}
53