Footer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 151
ccs 0
cts 58
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A boot() 0 8 1
A page() 0 4 1
A createOne() 0 20 1
A updateOne() 0 18 1
A getShowUrl() 0 4 1
A getEditUrl() 0 4 1
1
<?php namespace Arcanesoft\Seo\Models;
2
3
use Arcanedev\LaravelSeo\Traits\Seoable;
4
5
/**
6
 * Class     Footer
7
 *
8
 * @package  Arcanesoft\Seo\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  int             id
12
 * @property  int             page_id
13
 * @property  string          locale
14
 * @property  string          uri
15
 * @property  string          name
16
 * @property  string          localization
17
 * @property  \Carbon\Carbon  created_at
18
 * @property  \Carbon\Carbon  updated_at
19
 *
20
 * @property  \Arcanesoft\Seo\Models\Page  page
21
 */
22
class Footer extends AbstractModel
23
{
24
    /* -----------------------------------------------------------------
25
     |  Traits
26
     | -----------------------------------------------------------------
27
     */
28
29
    use Seoable,
30
        Presenters\FooterPresenter;
31
32
    /* -----------------------------------------------------------------
33
     |  Properties
34
     | -----------------------------------------------------------------
35
     */
36
37
    /**
38
     * The attributes that are mass assignable.
39
     *
40
     * @var array
41
     */
42
    protected $fillable = [
43
        'page_id', 'locale', 'uri', 'name', 'localization',
44
    ];
45
46
    /**
47
     * The attributes that should be cast to native types.
48
     *
49
     * @var array
50
     */
51
    protected $casts = [
52
        'id'      => 'integer',
53
        'page_id' => 'integer',
54
    ];
55
56
    /* -----------------------------------------------------------------
57
     |  Constructor
58
     | -----------------------------------------------------------------
59
     */
60
61
    /**
62
     * Footer constructor.
63
     *
64
     * @param  array  $attributes
65
     */
66
    public function __construct(array $attributes = [])
67
    {
68
        parent::__construct($attributes);
69
70
        $this->setConnection(config('arcanesoft.seo.database.connection'));
71
        $this->setPrefix(config('arcanesoft.seo.database.prefix', 'seo_'));
72
    }
73
74
    /**
75
     * The "booting" method of the model.
76
     *
77
     * @todo: Refactor to dedicated observer
78
     */
79
    protected static function boot()
80
    {
81
        parent::boot();
82
83
        self::deleting(function (Footer $footer) {
84
            $footer->deleteSeo();
85
        });
86
    }
87
88
    /* -----------------------------------------------------------------
89
     |  Relationships
90
     | -----------------------------------------------------------------
91
     */
92
93
    /**
94
     * Page's relationship.
95
     *
96
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
97
     */
98
    public function page()
99
    {
100
        return $this->belongsTo(Page::class);
101
    }
102
103
    /* -----------------------------------------------------------------
104
     |  Main Methods
105
     | -----------------------------------------------------------------
106
     */
107
108
    public static function createOne(array $attributes)
109
    {
110
        $footer = new self([
111
            'name'         => $attributes['name'],
112
            'localization' => $attributes['localization'],
113
            'uri'          => $attributes['uri'],
114
            'locale'       => $attributes['locale'],
115
            'page_id'      => $attributes['page'],
116
        ]);
117
118
        $footer->save();
119
120
        $footer->createSeo([
121
            'title'       => $attributes['seo_title'],
122
            'description' => $attributes['seo_description'],
123
            'keywords'    => $attributes['seo_keywords'],
124
        ]);
125
126
        return $footer;
127
    }
128
129
    public function updateOne(array $attributes)
130
    {
131
        $result = $this->update([
132
            'name'         => $attributes['name'],
133
            'localization' => $attributes['localization'],
134
            'uri'          => $attributes['uri'],
135
            'locale'       => $attributes['locale'],
136
            'page_id'      => $attributes['page'],
137
        ]);
138
139
        $this->updateSeo([
140
            'title'       => $attributes['seo_title'],
141
            'description' => $attributes['seo_description'],
142
            'keywords'    => $attributes['seo_keywords'],
143
        ]);
144
145
        return $result;
146
    }
147
148
    /* -----------------------------------------------------------------
149
     |  Other Methods
150
     | -----------------------------------------------------------------
151
     */
152
153
    /**
154
     * Get the show URL.
155
     *
156
     * @return string
157
     */
158
    public function getShowUrl()
159
    {
160
        return route('admin::seo.footers.show', [$this]);
161
    }
162
163
    /**
164
     * Get the edit URL.
165
     *
166
     * @return string
167
     */
168
    public function getEditUrl()
169
    {
170
        return route('admin::seo.footers.edit', [$this]);
171
    }
172
}
173