LayoutValue   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
eloc 13
c 2
b 0
f 0
dl 0
loc 37
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __toString() 0 3 1
A __get() 0 3 1
A attribute() 0 3 1
B layoutsAttribute() 0 15 7
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