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

JsonPathAccessor::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 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