Completed
Push — master ( 02e9e6...9b3fc3 )
by ARCANEDEV
09:52
created

Page   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 3
dl 0
loc 138
rs 10
c 0
b 0
f 0
ccs 0
cts 44
cp 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A footers() 0 4 1
A createOne() 0 7 1
A updateOne() 0 4 1
A isDeleteable() 0 4 1
A renderContent() 0 16 1
A getSelectInputData() 0 7 1
1
<?php namespace Arcanesoft\Seo\Models;
2
3
/**
4
 * Class     Page
5
 *
6
 * @package  Arcanesoft\Seo\Models
7
 * @author   ARCANEDEV <[email protected]>
8
 *
9
 * @property  int             id
10
 * @property  string          name
11
 * @property  string          content
12
 * @property  string          locale
13
 * @property  \Carbon\Carbon  created_at
14
 * @property  \Carbon\Carbon  updated_at
15
 *
16
 * @property  \Illuminate\Database\Eloquent\Collection  footers
17
 */
18
class Page extends AbstractModel
19
{
20
    /* -----------------------------------------------------------------
21
     |  Traits
22
     | -----------------------------------------------------------------
23
     */
24
    use Presenters\PagePresenter;
25
26
    /* -----------------------------------------------------------------
27
     |  Properties
28
     | -----------------------------------------------------------------
29
     */
30
    /**
31
     * The attributes that are mass assignable.
32
     *
33
     * @var array
34
     */
35
    protected $fillable = ['name', 'content', 'locale'];
36
37
    /**
38
     * The attributes that should be cast to native types.
39
     *
40
     * @var array
41
     */
42
    protected $casts = [
43
        'id' => 'integer',
44
    ];
45
46
    /* -----------------------------------------------------------------
47
     |  Constructor
48
     | -----------------------------------------------------------------
49
     */
50
    /**
51
     * Page constructor.
52
     *
53
     * @param  array  $attributes
54
     */
55
    public function __construct(array $attributes = [])
56
    {
57
        parent::__construct($attributes);
58
59
        $this->setConnection(config('arcanesoft.seo.database.connection'));
60
        $this->setPrefix(config('arcanesoft.seo.database.prefix', 'seo_'));
61
    }
62
63
    /* -----------------------------------------------------------------
64
     |  Relationships
65
     | -----------------------------------------------------------------
66
     */
67
    /**
68
     * Footer's relationship.
69
     *
70
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
71
     */
72
    public function footers()
73
    {
74
        return $this->hasMany(Footer::class);
75
    }
76
77
    /* -----------------------------------------------------------------
78
     |  Main Methods
79
     | -----------------------------------------------------------------
80
     */
81
    /**
82
     * Create a new page.
83
     *
84
     * @param  array  $attributes
85
     *
86
     * @return self
87
     */
88
    public static function createOne(array $attributes)
89
    {
90
        $page = new self($attributes);
91
        $page->save();
92
93
        return $page;
94
    }
95
96
    /**
97
     * Update a page.
98
     *
99
     * @param  array  $attributes
100
     *
101
     * @return bool
102
     */
103
    public function updateOne(array $attributes)
104
    {
105
        return $this->update($attributes);
106
    }
107
108
    /* -----------------------------------------------------------------
109
     |  Check Methods
110
     | -----------------------------------------------------------------
111
     */
112
    /**
113
     * Check if the page is deleteable.
114
     *
115
     * @return bool
116
     */
117
    public function isDeleteable()
118
    {
119
        return $this->footers->isEmpty();
120
    }
121
122
    /* -----------------------------------------------------------------
123
     |  Other Methods
124
     | -----------------------------------------------------------------
125
     */
126
    public function renderContent(array $replacer)
127
    {
128
        $content      = $this->content;
0 ignored issues
show
Unused Code introduced by
$content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
129
        $replacements = array_merge([
130
            'app_name' => config('app.name'),
131
            'app_url'  => link_to(config('app.url'), config('app.name')),
132
            'mobile'   => config('cms.company.mobile'),
133
            'phone'    => config('cms.company.phone'),
134
            'email'    => html()->mailto(config('cms.company.email')),
135
        ], $replacer);
136
137
        return strtr($this->content, array_combine(
138
            array_map(function ($from) { return "[{$from}]"; }, array_keys($replacements)),
139
            array_values($replacements)
140
        ));
141
    }
142
143
    /**
144
     * Get the select input data.
145
     *
146
     * @return \Illuminate\Database\Eloquent\Collection
147
     */
148
    public static function getSelectInputData()
149
    {
150
        $pages = Page::all(); // TODO: Cache the data ??
151
152
        return $pages->pluck('name', 'id')
153
            ->prepend('-- Select a page --', 0);
154
    }
155
}
156