Device::scopeOnHomePage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PiFinder;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Device extends Model
8
{
9
    protected $fillable = ['ip', 'name', 'mac', 'public', 'group'];
10
11 2
    public function scopeOnHomePage($query)
12
    {
13 2
        return $query->where('public', 'true')
14 2
                     ->orWhere(function ($query) {
15 2
                         $query->where('public', 'auto')
16 2
                               ->whereNull('group');
17 2
                     });
18
    }
19
20 5
    public function isPublic()
21
    {
22 5
        return $this->public == 'true' || ($this->public == 'auto' && $this->group === null);
23
    }
24
}
25