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

JsonPathAccessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 18 3
1
<?php
2
3
namespace Softonic\GraphQL\Traits;
4
5
trait JsonPathAccessor
6
{
7 52
    public function get(string $path)
8
    {
9 52
        if ($path == '.') {
10 48
            return $this;
11
        }
12
13 4
        $attributes = explode('.', $path);
14 4
        unset($attributes[0]);
15
16 4
        $attribute = array_shift($attributes);
17 4
        $value     = $this->{$attribute};
18
19 4
        if (!empty($attributes)) {
20 2
            $value = $value->get('.' . implode('.', $attributes));
21
        }
22
23 4
        return $value;
24
    }
25
}
26