Completed
Push — master ( 3f2c58...3eb51e )
by wen
02:00
created

HasAttributes   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 8 3
A getAttribute() 0 4 1
A merge() 0 6 1
1
<?php
2
3
4
namespace Sco\ActionLog\Traits;
5
6
trait HasAttributes
7
{
8
    protected $attributes = [];
9
10
    /**
11
     * Set a given log value.
12
     *
13
     * @param array|string $key
14
     * @param mixed        $value
15
     */
16
    public function setAttribute($key, $value = null)
17
    {
18
        $keys = is_array($key) ? $key : [$key => $value];
19
20
        foreach ($keys as $key => $value) {
21
            Arr::set($this->attributes, $key, $value);
22
        }
23
    }
24
25
    /**
26
     * Get the specified log value.
27
     *
28
     * @param null|string $key
29
     * @param mixed       $default
30
     *
31
     * @return mixed
32
     */
33
    public function getAttribute($key = null, $default = null)
34
    {
35
        return Arr::get($this->attributes, $key, $default);
36
    }
37
38
39
    public function merge(array $attributes)
40
    {
41
        $this->attributes = array_merge($this->attributes, $attributes);
42
43
        return $this;
44
    }
45
}
46