Test Setup Failed
Push — 0.9 ( dd36a2 )
by Ben
05:07
created

AssociatedAsset   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 3 1
A hasData() 0 3 1
A forgetData() 0 9 1
A setData() 0 9 1
1
<?php
2
3
namespace Thinktomorrow\AssetLibrary;
4
5
use Illuminate\Database\Eloquent\Relations\MorphPivot;
6
use Illuminate\Support\Arr;
7
8
class AssociatedAsset extends MorphPivot
9
{
10
    public $guarded = [];
11
    protected $casts = [
12
        'data' => 'array',
13
    ];
14
15
    public function hasData(string $key): bool
16
    {
17
        return Arr::has($this->data, $key);
18
    }
19
20
    public function getData(string $key, $default = null)
21
    {
22
        return Arr::get($this->data, $key, $default);
23
    }
24
25
    public function setData(string $name, $value): self
26
    {
27
        $data = $this->data;
28
29
        Arr::set($data, $name, $value);
30
31
        $this->data = $data;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Thinktomorrow\AssetLibrary\AssociatedAsset. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
32
33
        return $this;
34
    }
35
36
    public function forgetData(string $name): self
37
    {
38
        $data = $this->data;
39
40
        Arr::forget($data, $name);
41
42
        $this->data = $data;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Thinktomorrow\AssetLibrary\AssociatedAsset. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
43
44
        return $this;
45
    }
46
}
47