SeoData   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 52
ccs 13
cts 17
cp 0.7647
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A seoable() 0 4 1
A getSeoData() 0 12 3
A getSeoableModel() 0 4 1
A update() 0 4 1
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