Completed
Push — master ( 4e528e...b698b3 )
by ARCANEDEV
04:17
created

Participant   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A discussion() 0 6 1
A user() 0 6 1
A stringInfo() 0 4 1
1
<?php namespace Arcanedev\LaravelMessenger\Models;
2
3
use Arcanedev\LaravelMessenger\Bases\Model;
4
use Arcanedev\LaravelMessenger\Contracts\Participant as ParticipantContract;
5
use Illuminate\Database\Eloquent\SoftDeletes;
6
7
/**
8
 * Class     Participant
9
 *
10
 * @package  Arcanedev\LaravelMessenger\Models
11
 * @author   ARCANEDEV <[email protected]>
12
 *
13
 * @property  int                                            id
14
 * @property  int                                            discussion_id
15
 * @property  \Arcanedev\LaravelMessenger\Models\Discussion  discussion
16
 * @property  int                                            user_id
17
 * @property  \Illuminate\Database\Eloquent\Model            user
18
 * @property  \Carbon\Carbon                                 last_read
19
 * @property  \Carbon\Carbon                                 created_at
20
 * @property  \Carbon\Carbon                                 updated_at
21
 * @property  \Carbon\Carbon                                 deleted_at
22
 */
23
class Participant extends Model implements ParticipantContract
24
{
25
    /* ------------------------------------------------------------------------------------------------
26
     |  Traits
27
     | ------------------------------------------------------------------------------------------------
28
     */
29
    use SoftDeletes;
30
31
    /* ------------------------------------------------------------------------------------------------
32
     |  Properties
33
     | ------------------------------------------------------------------------------------------------
34
     */
35
    /**
36
     * The attributes that can be set with Mass Assignment.
37
     *
38
     * @var array
39
     */
40
    protected $fillable = ['discussion_id', 'user_id', 'last_read'];
41
42
    /**
43
     * The attributes that should be mutated to dates.
44
     *
45
     * @var array
46
     */
47
    protected $dates = ['last_read', 'deleted_at'];
48
49
    /**
50
     * The attributes that should be cast to native types.
51
     *
52
     * @var array
53
     */
54
    protected $casts = [
55
        'discussion_id' => 'integer',
56
        'user_id'       => 'integer',
57
    ];
58
59
    /* ------------------------------------------------------------------------------------------------
60
     |  Constructor
61
     | ------------------------------------------------------------------------------------------------
62
     */
63
    /**
64
     * Create a new Eloquent model instance.
65
     *
66
     * @param  array  $attributes
67
     */
68
    public function __construct(array $attributes = [])
69
    {
70
        $this->setTable(
71
            $this->getTableFromConfig('participants', 'participants')
72
        );
73
74
        parent::__construct($attributes);
75
    }
76
77
    /* ------------------------------------------------------------------------------------------------
78
     |  Relationships
79
     | ------------------------------------------------------------------------------------------------
80
     */
81
    /**
82
     * Discussion relationship.
83
     *
84
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
85
     */
86
    public function discussion()
87
    {
88
        return $this->belongsTo(
89
            $this->getModelFromConfig('discussions', Discussion::class)
90
        );
91
    }
92
93
    /**
94
     * User relationship.
95
     *
96
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
97
     */
98
    public function user()
99
    {
100
        return $this->belongsTo(
101
            $this->getModelFromConfig('users')
102
        );
103
    }
104
105
    /* ------------------------------------------------------------------------------------------------
106
     |  Getters & Setters
107
     | ------------------------------------------------------------------------------------------------
108
     */
109
    /**
110
     * Get the participant string info.
111
     *
112
     * @return string
113
     */
114
    public function stringInfo()
115
    {
116
        return $this->user->name;
117
    }
118
}
119