SeoData::getSeoData()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 3
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace MadWeb\Seoable\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use MadWeb\Seoable\Contracts\SeoDataContract;
7
8
class SeoData extends Model implements SeoDataContract
9
{
10
    /** @var array */
11
    protected $fillable = [
12
        'meta',
13
        'open_graph',
14
        'twitter',
15
    ];
16
17
    /** @var array */
18
    protected $casts = [
19
        'meta' => 'array',
20
        'open_graph' => 'array',
21
        'twitter' => 'array',
22
    ];
23
24 27
    public function __construct(array $attributes = [])
25
    {
26 27
        parent::__construct($attributes);
27
28 27
        $this->setTable(config('seoable.seo_data_table'));
29 27
    }
30
31
    public function seoable()
32
    {
33
        return $this->morphTo();
34
    }
35
36 6
    public function getSeoData(): array
37
    {
38 6
        $meta = $this->meta;
39 6
        $open_graph = $this->open_graph;
40 6
        $twitter_card = $this->twitter_card;
41
42 6
        $meta += ['open_graph' => ! empty($open_graph) ? $open_graph : []];
43
44 6
        $meta += ['twitter_card' => ! empty($twitter_card) ? $twitter_card : []];
45
46 6
        return $meta;
47
    }
48
49
    public function getSeoableModel(): string
50
    {
51
        return $this->seoable_type;
52
    }
53
54
    /** {@inheritdoc} */
55 12
    public function update(array $attributes = [], array $options = [])
56
    {
57 12
        return $this->fill($attributes)->save($options);
58
    }
59
}
60