Passed
Pull Request — master (#39)
by
unknown
04:26
created

Articles::cutStr()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 getCat($str)
71
    {
72
        switch ($str) {
73
            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...
74
            case "obat":        return "Obat - obatan"; break;
75
            case "hidup-sehat": return "Hidup Sehat";   break;
76
            case "keluarga":    return "Keluarga";      break;
77
            case "kesehatan":   return "Kesehatan";     break;
78
        }
79
    }
80
}
81