HasAttributes   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
eloc 17
dl 0
loc 62
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setRawAttributes() 0 5 1
A all() 0 3 1
A __get() 0 3 1
A __set() 0 3 1
A has() 0 3 1
A fill() 0 9 1
A except() 0 3 2
A only() 0 3 2
A get() 0 3 1
A set() 0 5 1
1
<?php
2
3
namespace Larapie\Actions\Concerns;
4
5
use Illuminate\Support\Arr;
6
7
trait HasAttributes
8
{
9
    protected $attributes = [];
10
11 1
    public function setRawAttributes(array $attributes)
12
    {
13 1
        $this->attributes = $attributes;
14
15 1
        return $this;
16
    }
17
18 68
    public function fill(array $attributes)
19
    {
20 68
        $attributes = array_merge($attributes, $this->resolveAttributeCasting($attributes));
0 ignored issues
show
Bug introduced by
It seems like resolveAttributeCasting() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $attributes = array_merge($attributes, $this->/** @scrutinizer ignore-call */ resolveAttributeCasting($attributes));
Loading history...
21
22 68
        $attributes = array_merge($this->attributes, $attributes);
23
24 68
        $this->attributes = array_merge($this->resolveDefaults(), $attributes);
0 ignored issues
show
Bug introduced by
It seems like resolveDefaults() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $this->attributes = array_merge($this->/** @scrutinizer ignore-call */ resolveDefaults(), $attributes);
Loading history...
25
26 68
        return $this;
27
    }
28
29 55
    public function all()
30
    {
31 55
        return $this->attributes;
32
    }
33
34 1
    public function only($keys)
35
    {
36 1
        return Arr::only($this->attributes, is_array($keys) ? $keys : func_get_args());
37
    }
38
39 1
    public function except($keys)
40
    {
41 1
        return Arr::except($this->attributes, is_array($keys) ? $keys : func_get_args());
42
    }
43
44 7
    public function has($key)
45
    {
46 7
        return Arr::has($this->attributes, $key);
47
    }
48
49 14
    public function get($key, $default = null)
50
    {
51 14
        return Arr::get($this->attributes, $key, $default);
52
    }
53
54 1
    public function set($key, $value)
55
    {
56 1
        Arr::set($this->attributes, $key, $value);
57
58 1
        return $this;
59
    }
60
61 14
    public function __get($key)
62
    {
63 14
        return $this->get($key);
64
    }
65
66 1
    public function __set($key, $value)
67
    {
68 1
        $this->set($key, $value);
69 1
    }
70
}
71