Completed
Push — master ( e600ef...7ac924 )
by Basenko
07:00
created

SeoData   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 26.67%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 46
ccs 4
cts 15
cp 0.2667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A seoable() 0 4 1
A getSeoableModel() 0 4 1
A getSeoData() 0 12 3
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 9
    public function __construct(array $attributes = [])
25
    {
26 9
        parent::__construct($attributes);
27
28 9
        $this->setTable(config('seoable.seo_data_table'));
29 9
    }
30
31
    public function seoable()
32
    {
33
        return $this->morphTo();
34
    }
35
36
    public function getSeoData(): array
37
    {
38
        $meta = $this->meta;
39
        $open_graph = $this->open_graph;
40
        $twitter_card = $this->twitter_card;
41
42
        $meta += ['open_graph' => ! empty($open_graph) ? $open_graph : []];
43
44
        $meta += ['twitter_card' => ! empty($twitter_card) ? $twitter_card : []];
45
46
        return $meta;
47
    }
48
49
    public function getSeoableModel(): string
50
    {
51
        return $this->seoable_type;
52
    }
53
}
54