Completed
Pull Request — develop (#44)
by Daniel
12:17 queued 06:11
created

Device::logo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
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
31
    // ---- Accessors/Mutators ----
32
33
    public function getIpAttribute($ip)
34
    {
35
        if (!empty($ip)) {
36
            return inet_ntop($ip);
37
        }
38
    }
39
40
    public function setIpAttribute($ip)
41
    {
42
        $this->attributes['ip'] = inet_pton($ip);
43
    }
44
45
46
    // ---- Define Reletionships ----
47
48
    /**
49
     * Returns a list of users that can access this device.
50
     */
51
    public function users() {
52
        return $this->belongsToMany('App\User', 'devices_perms', 'device_id', 'user_id');
53
    }
54
55
    /**
56
     * Returns a list of the ports this device has.
57
     */
58
    public function ports() {
59
        return $this->hasMany('App\Port', 'device_id', 'device_id');
60
    }
61
62
    /**
63
     * Returns a list of the Syslog entries this device has.
64
     */
65
    public function syslogs() {
66
        return $this->hasMany('App\Syslog', 'device_id', 'device_id');
67
    }
68
69
    /**
70
     * Returns a list of the Eventlog entries this device has.
71
     */
72
    public function eventlogs() {
73
        return $this->hasMany('App\Eventlog', 'device_id', 'device_id');
74
    }
75
76
    /**
77
     * Return URI to logo picture
78
     */
79
    public function logo() {
80
        $os = DeviceOS::load($this);
81
        if( isset($os->icon) ){
82
            return asset('images/os/'.$os->icon.'.png');
0 ignored issues
show
Bug introduced by
The property icon does not seem to exist in App\DeviceOS.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
83
        }
84
        return asset('images/os/generic.png');
85
    }
86
}
87