LayoutValue::__get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NovaThinKit\Nova\Flexible\Resolvers;
4
5
use Illuminate\Support\Arr;
6
7
class LayoutValue implements \Stringable
8
{
9 5
    public function __construct(
10
        protected array $data
11
    ) {
12 5
    }
13
14 3
    public function __get(string $name)
15
    {
16 3
        return Arr::get($this->data, $name);
17
    }
18
19 2
    public function attribute(string $key): mixed
20
    {
21 2
        return Arr::get($this->data, "attributes.{$key}");
22
    }
23
24 1
    public function layoutsAttribute(string $key): array
25
    {
26 1
        $value = $this->attribute($key);
27 1
        if($value && is_array($value)) {
28 1
            return array_values(array_filter(array_map(function ($item) {
29 1
                $layoutValue = new LayoutValue(!is_array($item) ? (array)$item : $item);
30 1
                if($layoutValue->layout && $layoutValue->key && is_array($layoutValue->attributes)) {
0 ignored issues
show
Bug Best Practice introduced by
The property layout does not exist on NovaThinKit\Nova\Flexible\Resolvers\LayoutValue. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property key does not exist on NovaThinKit\Nova\Flexible\Resolvers\LayoutValue. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property attributes does not exist on NovaThinKit\Nova\Flexible\Resolvers\LayoutValue. Since you implemented __get, consider adding a @property annotation.
Loading history...
31 1
                    return $layoutValue;
32
                }
33
34 1
                return null;
35 1
            }, $value)));
36
        }
37
38 1
        return [];
39
    }
40
41 1
    public function __toString(): string
42
    {
43 1
        return json_encode($this->data);
44
    }
45
}
46