CloudStorage::getUserEmail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace STS\StorageConnect\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use STS\StorageConnect\Exceptions\StorageUnavailableException;
7
8
/**
9
 * Class CloudStorage
10
 *
11
 * @property int $id
12
 * @property int $owner_id
13
 * @property string $owner_type
14
 * @property string $owner_description
15
 * @property Model $owner
16
 * @property string $name
17
 * @property string $email
18
 */
19
class CloudStorage extends Model
20
{
21
    use Concerns\UploadsFiles,
22
        Concerns\TracksQuota,
23
        Concerns\HasStorageAdapter,
24
        Concerns\ManagesStorageConnection;
25
26
    const SPACE_FULL = "full";
27
    const INVALID_TOKEN = "invalid";
28
29
    /**
30
     * @var array
31
     */
32
    protected $guarded = [];
33
34
    /**
35
     * @var array
36
     */
37
    protected $casts = [
38
        'token'     => 'array',
39
        'connected' => 'boolean',
40
        'enabled'   => 'boolean',
41
        'full'      => 'boolean',
42
    ];
43
44
    /**
45
     * @var array
46
     */
47
    protected $dates = [
48
        'space_checked_at',
49
        'uploaded_at',
50
        'disabled_at',
51
        'enabled_at'
52
    ];
53
54
    /**
55
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
56
     */
57
    public function owner()
58
    {
59
        return $this->morphTo();
60
    }
61
62
    /**
63
     * If we have an owner, use the owning model name and identifier.
64
     * Otherwise we'll have to just use the cloud storage email address.
65
     *
66
     * @return string
67
     */
68
    public function getOwnerDescriptionAttribute()
69
    {
70
        return $this->owner
71
            ? array_reverse(explode("\\", $this->owner_type))[0] . ":" . $this->owner_id
72
            : $this->email;
73
    }
74
75
    /**
76
     * @return mixed
77
     */
78
    public function getUserName()
79
    {
80
        return $this->name;
81
    }
82
83
    /**
84
     * @return mixed
85
     */
86
    public function getUserEmail()
87
    {
88
        return $this->email;
89
    }
90
}