TrackableResourceModel::setMetaAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace BoxedCode\Tracking;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class TrackableResourceModel extends Model
8
{
9
    /**
10
     * The table associated with the model.
11
     *
12
     * @var string
13
     */
14
    protected $table = 'trackable_resources';
15
16
    /**
17
     * Indicates if the IDs are auto-incrementing.
18
     *
19
     * @var bool
20
     */
21
    public $incrementing = false;
22
23
    /**
24
     * The attributes that are mass assignable.
25
     *
26
     * @var array
27
     */
28
    protected $fillable = ['id', 'type', 'resource', 'meta'];
29
30
    /**
31
     * Set the meta data attribute.
32
     *
33
     * @param array $value
34
     */
35 3
    public function setMetaAttribute($value = [])
36
    {
37 3
        if (! is_null($value)) {
38 3
            $this->attributes['meta'] = serialize($value);
39 3
        } else {
40 1
            $this->attributes['meta'] = null;
41
        }
42 3
    }
43
44
    /**
45
     * Get the meta data attribute.
46
     *
47
     * @return mixed
48
     */
49 5
    public function getMetaAttribute()
50
    {
51 5
        if (isset($this->attributes['meta']) && ! empty($this->attributes['meta'])) {
52 2
            return unserialize($this->attributes['meta']);
53
        }
54 3
    }
55
}
56