Completed
Pull Request — develop (#11)
by
unknown
17:54 queued 10:02
created

Devices   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIpAttribute() 0 6 2
A setIpAttribute() 0 4 1
A users() 0 3 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Devices extends Model
8
{
9
    protected $table = 'devices';
10
    protected $primaryKey = 'device_id';
11
12
    /**
13
     * Indicates if the model should be timestamped.
14
     *
15
     * @var bool
16
     */
17
    public $timestamps = false;
18
19
    public function getIpAttribute( $ip )
20
    {
21
        if (!empty($ip)){
22
            return inet_ntop( $ip );
23
        }
24
    }
25
26
    public function setIpAttribute( $ip )
27
    {
28
        $this->attributes['ip'] = inet_pton( $ip );
29
    }
30
31
    // -- Define Reletionships --
32
33
    /**
34
     * Returns a list of users that can access this device
35
     */
36
    public function users() {
37
        return $this->belongsToMany('App\User', 'devices_perms', 'device_id', 'user_id');
38
    }
39
}
40