Topic::title()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Entities;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Collection;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\SoftDeletes;
9
10
/**
11
 * Class Topic.
12
 *
13
 * @property int $id
14
 * @property int $contest_id
15
 * @property int $problem_id
16
 * @property int $user_id
17
 * @property string $title
18
 * @property string $content
19
 * @property Carbon $created_at
20
 * @property Carbon $updated_at
21
 * @property-read Reply[]|Collection $replies
22
 */
23
class Topic extends Model
24
{
25
    use SoftDeletes;
26
27
    protected $fillable = [
28
        'contest_id',
29
        'user_id',
30
        'problem_id',
31
        'title',
32
        'content',
33
    ];
34
35
    public function showProblemId()
36
    {
37
        if ($this->problem_id < 100 && $this->contest_id) {
38
            return show_order($this->problem_id);
39
        }
40
41
        return $this->problem_id;
42
    }
43
44
    public function title($default = 'untitle')
45
    {
46
        if ($this->title) {
47
            return $this->title;
48
        }
49
50
        return $default;
51
    }
52
53
    public function user()
54
    {
55
        return $this->belongsTo(User::class);
56
    }
57
58
    public function contest()
59
    {
60
        return $this->belongsTo(Contest::class);
61
    }
62
63
    public function replies()
64
    {
65
        return $this->hasMany(Reply::class);
66
    }
67
}
68