Completed
Push — develop ( 5f1168...aa9d13 )
by Daniel
05:30
created

Device   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIpAttribute() 0 6 2
A setIpAttribute() 0 4 1
A users() 0 3 1
A ports() 0 3 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Device extends Model
8
{
9
    /**
10
     * The table associated with the model.
11
     *
12
     * @var string
13
     */
14
    protected $table = 'devices';
15
16
    /**
17
     * The primary key column name.
18
     *
19
     * @var string
20
     */
21
    protected $primaryKey = 'device_id';
22
23
    /**
24
     * Indicates if the model should be timestamped.
25
     *
26
     * @var bool
27
     */
28
    public $timestamps = false;
29
30
    public function getIpAttribute($ip)
31
    {
32
        if (!empty($ip)) {
33
            return inet_ntop($ip);
34
        }
35
    }
36
37
    public function setIpAttribute($ip)
38
    {
39
        $this->attributes['ip'] = inet_pton($ip);
40
    }
41
42
    // ---- Define Reletionships ----
43
44
    /**
45
     * Returns a list of users that can access this device.
46
     */
47
    public function users() {
48
        return $this->belongsToMany('App\User', 'devices_perms', 'device_id', 'user_id');
49
    }
50
51
    /**
52
     * Returns a list of the ports this device has.
53
     */
54
    public function ports() {
55
        return $this->hasMany('App\Port', 'device_id', 'device_id');
56
    }
57
58
}
59