Completed
Push — master ( 81034a...b50ff0 )
by Faiq
20s queued 11s
created

Articles   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCat() 0 8 6
A writer() 0 15 3
A admin() 0 2 1
A doctor() 0 2 1
A cutStr() 0 6 2
1
<?php
2
3
namespace App;
4
5
use App\Doctor;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Articles extends Model
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $table = 'articles';
14
15
    /**
16
     * @var string
17
     */
18
    public $primaryKey = 'id';
19
20
    /**
21
     * @var bool
22
     */
23
    public $timestamps = true;
24
25
    /**
26
     * @var array
27
     */
28
    protected $dates = [
29
        'created_at',
30
        'updated_at'
31
    ];
32
33
    /**
34
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
35
     */
36
    public function admin() {
37
        return $this->belongsTo('App\Admin');
38
    }
39
40
41
    /**
42
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
43
     */
44
    public function doctor() {
45
        return $this->belongsTo('App\Doctor');
46
    }
47
48
    /**
49
     * @param $id
50
     * @return array
51
     */
52
    public function writer() {
53
        $adminId = $this->getAttributeValue('admin_id');
54
        $doctorId = $this->getAttributeValue('doctor_id');
55
56
        $writer = ['role', 'data'];
57
58
        if($adminId != null) {
59
            $writer['role'] = "Admin";
60
            $writer['data'] = Admin::find($adminId);
61
        } elseif($doctorId != null) {
62
            $writer['role'] = "Dokter";
63
            $writer['data'] = Doctor::find($doctorId);
64
        }
65
66
        return $writer;
67
    }
68
69
    /**
70
     * @param $str
71
     * @return string
72
     */
73
    public function cutStr($str)
74
    {
75
        if (strlen($str) > 200){
76
            return substr($str,0,200) . "...";
77
        }
78
        return $str;
79
    }
80
81
    /**
82
     * @param $str
83
     * @return string
84
     */
85
    public function getCat($str)
86
    {
87
        switch ($str) {
88
            case "penyakit":    return "Penyakit";      break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
89
            case "obat":        return "Obat - obatan"; break;
90
            case "hidup-sehat": return "Hidup Sehat";   break;
91
            case "keluarga":    return "Keluarga";      break;
92
            case "kesehatan":   return "Kesehatan";     break;
93
        }
94
    }
95
}
96