Completed
Push — master ( 786b39...7594a2 )
by wen
03:20
created

HasAttributes::setAttribute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 4
nop 2
1
<?php
2
3
4
namespace Sco\Admin\Traits;
5
6
use Illuminate\Support\Arr;
7
8
trait HasAttributes
9
{
10
    protected $attributes = [];
11
12
    /**
13
     * Set a given log value.
14
     *
15
     * @param array|string $key
16
     * @param mixed        $value
17
     */
18
    public function setAttribute($key, $value = null)
19
    {
20
        $keys = is_array($key) ? $key : [$key => $value];
21
22
        foreach ($keys as $key => $value) {
23
            Arr::set($this->attributes, $key, $value);
24
        }
25
    }
26
27
    /**
28
     * Get the specified log value.
29
     *
30
     * @param null|string $key
31
     * @param mixed       $default
32
     *
33
     * @return mixed
34
     */
35
    public function getAttribute($key = null, $default = null)
36
    {
37
        return Arr::get($this->attributes, $key, $default);
38
    }
39
40
41
    public function merge(array $attributes)
42
    {
43
        $this->attributes = array_merge($this->attributes, $attributes);
44
45
        return $this;
46
    }
47
}
48