Completed
Branch master (59afb3)
by Adam
05:44
created

Tag::getLogoAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Coyote;
4
5
use Coyote\Services\Media\Factory as MediaFactory;
6
use Coyote\Services\Media\Logo;
7
use Coyote\Services\Media\MediaInterface;
8
use Coyote\Tag\Category;
9
use Illuminate\Database\Eloquent\Model;
10
use Illuminate\Database\Eloquent\SoftDeletes;
11
12
/**
13
 * @property int $id
14
 * @property string $name
15
 * @property string $real_name
16
 * @property int $category_id
17
 * @property Category $category
18
 * @property MediaInterface $logo
19
 */
20
class Tag extends Model
21
{
22
    use SoftDeletes;
23
24
    /**
25
     * The attributes that are mass assignable.
26
     *
27
     * @var array
28
     */
29
    protected $fillable = ['name', 'real_name', 'category_id'];
30
31
    /**
32
     * @var array
33
     */
34
    protected $dates = ['created_at', 'deleted_at'];
35
36
    /**
37
     * @var string
38
     */
39
    protected $dateFormat = 'Y-m-d H:i:se';
40
41
    /**
42
     * @var bool
43
     */
44
    public $timestamps = false;
45
46
    /**
47
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
48
     */
49
    public function category()
50
    {
51
        return $this->belongsTo(Category::class);
52
    }
53
54
    /**
55
     * @param string $value
56
     * @return \Coyote\Services\Media\MediaInterface
57
     */
58 View Code Duplication
    public function getLogoAttribute($value)
59
    {
60
        if (!($value instanceof Logo)) {
61
            $logo = app(MediaFactory::class)->make('logo', ['file_name' => $value]);
62
            $this->attributes['logo'] = $logo;
63
        }
64
65
        return $this->attributes['logo'];
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function __toString()
72
    {
73
        return $this->name;
74
    }
75
}
76