Passed
Push — master ( d4d422...838e2d )
by Faiq
04:09
created

Articles::admin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
     * @param $id
35
     * @return array
36
     */
37
    public function writer() {
38
        $adminId = $this->getAttributeValue('admin_id');
39
        $doctorId = $this->getAttributeValue('doctor_id');
40
41
        $writer = ['role', 'data'];
42
43
        if($adminId != null) {
44
            $writer['role'] = "Admin";
45
            $writer['data'] = Admin::find($adminId);
46
        } elseif($doctorId != null) {
47
            $writer['role'] = "Dokter";
48
            $writer['data'] = Doctor::find($doctorId);
49
        }
50
51
        return $writer;
52
    }
53
54
    /**
55
     * @param $str
56
     * @return string
57
     */
58
    public function cutStr($str)
59
    {
60
        if (strlen($str) > 200){
61
            return substr($str,0,200) . "...";
62
        }
63
        return $str;
64
    }
65
66
    /**
67
     * @param $str
68
     * @return string
69
     */
70
    public function trimStr($str)
71
    {
72
        if(strlen($str) > 20) {
73
            return substr($str, 0, 20) . "...";
74
        }
75
        return $str;
76
    }
77
78
    /**
79
     * @param $str
80
     * @return string
81
     */
82
    public function getCat($str)
83
    {
84
        switch ($str) {
85
            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...
86
            case "obat":        return "Obat - obatan"; break;
87
            case "hidup-sehat": return "Hidup Sehat";   break;
88
            case "keluarga":    return "Keluarga";      break;
89
            case "kesehatan":   return "Kesehatan";     break;
90
        }
91
    }
92
}
93