Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#122)
by Mark
22:40 queued 02:31
created

Plugin::disable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Mark
5
 * Date: 05/03/2016
6
 * Time: 14:42.
7
 */
8
9
namespace App\Model;
10
11
use App\Plugins\PluginHandler;
12
use Illuminate\Database\Eloquent\Model as EloquentModel;
13
14
/**
15
 * Class Plugins.
16
 *
17
 * @property string $name
18
 *
19
 * @property bool $required
20
 * @property bool $enabled
21
 *
22
 * @property PluginHandler $handler
23
 *
24
 * @property Plugin $options
25
 */
26
class Plugin extends EloquentModel
27
{
28
    /**
29
     * The table associated with the model.
30
     *
31
     * @var string
32
     */
33
    protected $table = 'plugins';
34
35
    /**
36
     * The attributes that are mass assignable.
37
     *
38
     * @var array
39
     */
40
    protected $fillable = [];
41
42
    /**
43
     * The table date columns, casted to Carbon.
44
     *
45
     * @var array
46
     */
47
    protected $dates = ['created_at', 'updated_at'];
48
49
    /**
50
     * The attributes that should be cast to native types.
51
     *
52
     * @var array
53
     */
54
    protected $casts = ['enabled' => 'boolean', 'required' => 'boolean'];
55
56
    /**
57
     * Return the plugins namespace.
58
     *
59
     * @return string
60
     */
61
    protected function dirNamespace()
62
    {
63
        return sprintf("App\Plugins\%s", ucfirst($this->name));
64
    }
65
66
    /**
67
     * @return PluginHandler
68
     */
69
    protected function getHandlerAttribute()
70
    {
71
        return app(sprintf("%s\%sController", $this->dirNamespace(), ucfirst($this->name)));
72
    }
73
74
    /**
75
     * ==========================================================.
76
     *
77
     *   GET THE ATTRIBUTES OF THE MODEL
78
     *
79
     * ==========================================================
80
     */
81
    public function icon()
82
    {
83
        return $this->handler->icon();
84
    }
85
86
    public function name()
87
    {
88
        return $this->name;
89
    }
90
91
    public function version()
92
    {
93
        return $this->handler->version();
94
    }
95
96
    public function isEnabled()
97
    {
98
        return $this->getAttribute('enabled') == true;
99
    }
100
101
    public function isDisabled()
102
    {
103
        return $this->getAttribute('enabled') == false;
104
    }
105
106
    public function isFrontEnd()
107
    {
108
        return $this->getAttribute('is_frontend');
109
    }
110
111
    public function isBackEnd()
112
    {
113
        return $this->getAttribute('is_backend');
114
    }
115
116
    public function getCreatedAt()
117
    {
118
        return $this->getAttribute('created_at');
119
    }
120
121
    public function getUpdatedAt()
122
    {
123
        return $this->getAttribute('updated_at');
124
    }
125
126
    public function setEnabled($boolean)
127
    {
128
        if ($boolean == true) {
129
            return $this->enable();
130
        }
131
132
        return $this->disable();
133
    }
134
135
    /**
136
     * Enable the product.
137
     *
138
     * @return $this
139
     */
140
    public function enable()
141
    {
142
        $this->setAttribute('enabled', true);
143
144
        return $this;
145
    }
146
147
    /**
148
     * Disable the product.
149
     *
150
     * @return $this
151
     */
152
    public function disable()
153
    {
154
        $this->setAttribute('enabled', false);
155
156
        return $this;
157
    }
158
159
    public function setInstalled(bool $boolean)
160
    {
161
        $this->setAttribute('installed', $boolean ? 1 : 0);
162
163
        return $this;
164
    }
165
166
    /**
167
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
168
     */
169
    public function isInstalled()
170
    {
171
        return $this->getAttribute('installed') ? true : false;
172
    }
173
174
    public function setName($string)
175
    {
176
        $this->setAttribute('name', $string);
177
178
        return $this;
179
    }
180
181
    public function setVersion($integer)
182
    {
183
        $this->setAttribute('version', $integer);
184
185
        return $this;
186
    }
187
188
    public function setIcon($string)
189
    {
190
        $this->setAttribute('icon', $string);
191
192
        return $this;
193
    }
194
195
    public function adminUrl()
196
    {
197
        if ($this->isBackEnd()) {
198
            return url('/admin/'.$this->name());
199
        }
200
201
        throw new \Exception('This is not a backend enabled plugin and should not be used here.');
202
    }
203
204
    public function userUrl()
205
    {
206
        if ($this->isFrontEnd()) {
207
            return url($this->name());
208
        }
209
210
        throw new \Exception('This is not a frontend enabled plugin and should not be used here.');
211
    }
212
213
    public function isHidden()
214
    {
215
        return $this->getAttribute('hidden') ? true : false;
216
    }
217
218
    public function setHide(bool $boolean)
219
    {
220
        $this->setAttribute('hidden', $boolean ? 1 : 0);
221
222
        return $this;
223
    }
224
225
    public function setRequired($boolean)
226
    {
227
        $this->setAttribute('required', $boolean);
228
229
        return $this;
230
    }
231
232
    public function setFrontEnd($boolean)
233
    {
234
        $this->setAttribute('is_frontend', $boolean);
235
236
        return $this;
237
    }
238
239
    public function setBackEnd($boolean)
240
    {
241
        $this->setAttribute('is_backend', $boolean);
242
243
        return $this;
244
    }
245
246
    /**
247
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
248
     */
249
    public function options()
250
    {
251
        return $this->hasMany(PluginOption::class, 'plugin_id', 'id');
252
    }
253
254
    public function option($key)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
255
    {
256
        return $this->options->where('key', $key)->first()->value();
257
    }
258
259
    public function feeds()
260
    {
261
        return $this->hasMany(PluginFeed::class, 'plugin_id', 'id');
262
    }
263
264
    public function install()
265
    {
266
        $controller = app(printf("App\Plugins\%s", $this->name));
267
268
        $controller->install();
269
    }
270
}
271