Completed
Push — master ( 5515a8...305b61 )
by Renato
10s
created

Issue::notes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
9
namespace GitScrum\Models;
10
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Database\Eloquent\SoftDeletes;
13
use Carbon\Carbon;
14
use GitScrum\Scopes\GlobalScope;
15
16
class Issue extends Model
17
{
18
    use SoftDeletes;
19
    use GlobalScope;
20
    /**
21
     * The database table used by the model.
22
     *
23
     * @var string
24
     */
25
    protected $table = 'issues';
26
27
    /**
28
     * Attributes that should be mass-assignable.
29
     *
30
     * @var array
31
     */
32
    protected $fillable = ['config_issue_effort_id', 'issue_type_id', 'provider_id', 'provider', 'user_id', 'product_backlog_id', 'parent_id',
33
        'branch_id', 'sprint_id', 'user_story_id', 'number', 'effort', 'slug', 'code', 'title', 'description', 'state',
34
        'config_status_id', 'position', 'is_planning_poker', 'closed_user_id', 'closed_at', ];
35
36
    /**
37
     * The attributes excluded from the model's JSON form.
38
     *
39
     * @var array
40
     */
41
    protected $hidden = [];
42
43
    /**
44
     * The attributes that should be casted to native types.
45
     *
46
     * @var array
47
     */
48
    protected $casts = [];
49
50
    protected $dates = ['deleted_at'];
51
52
    protected static function boot()
53
    {
54
        parent::boot();
55
    }
56
57
    public function branch()
58
    {
59
        return $this->belongsTo(\GitScrum\Models\Branch::class, 'branch_id', 'id');
60
    }
61
62
    public function type()
63
    {
64
        return $this->belongsTo(\GitScrum\Models\IssueType::class, 'issue_type_id', 'id');
65
    }
66
67
    public function configEffort()
68
    {
69
        return $this->belongsTo(\GitScrum\Models\ConfigIssueEffort::class, 'config_issue_effort_id', 'id');
70
    }
71
72
    public function sprint()
73
    {
74
        return $this->belongsTo(\GitScrum\Models\Sprint::class, 'sprint_id', 'id');
75
    }
76
77
    public function productBacklog()
78
    {
79
        return $this->belongsTo(\GitScrum\Models\ProductBacklog::class, 'product_backlog_id', 'id');
80
    }
81
82
    public function userStory()
83
    {
84
        return $this->belongsTo(\GitScrum\Models\UserStory::class, 'user_story_id', 'id');
85
    }
86
87
    public function user()
88
    {
89
        return $this->belongsTo(\GitScrum\Models\User::class, 'user_id', 'id');
90
    }
91
92
    public function closedUser()
93
    {
94
        return $this->belongsTo(\GitScrum\Models\User::class, 'closed_user_id', 'id');
95
    }
96
97
    public function users()
98
    {
99
        return $this->belongsToMany(\GitScrum\Models\User::class, 'issues_has_users', 'issue_id', 'user_id');
100
    }
101
102
    public function commits()
103
    {
104
        return $this->hasMany(\GitScrum\Models\Commit::class, 'issue_id', 'id');
105
    }
106
107
    public function comments()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
108
    {
109
        return $this->morphMany(\GitScrum\Models\Comment::class, 'commentable')
110
            ->orderby('created_at', 'DESC');
111
    }
112
113
    public function attachments()
114
    {
115
        return $this->morphMany(\GitScrum\Models\Attachment::class, 'attachmentable');
116
    }
117
118
    public function notes()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
119
    {
120
        return $this->morphMany(\GitScrum\Models\Note::class, 'noteable')
121
            ->orderby('position', 'ASC');
122
    }
123
124
    public function favorite()
125
    {
126
        return $this->morphOne(\GitScrum\Models\Favorite::class, 'favoriteable');
127
    }
128
129
    public function labels()
130
    {
131
        return $this->morphToMany(\GitScrum\Models\Label::class, 'labelable');
132
    }
133
134
    public function status()
135
    {
136
        return $this->hasOne(\GitScrum\Models\ConfigStatus::class, 'id', 'config_status_id');
137
    }
138
139
    public function statuses()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
140
    {
141
        return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable')
142
            ->orderby('created_at', 'DESC');
143
    }
144
145
    public function dateForHumans($dateField = 'created_at')
146
    {
147
        return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes[$dateField])->diffForHumans();
148
    }
149
150
    public function getNumberAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
151
    {
152
        return isset($this->attributes['number']) ? $this->attributes['number'] : null;
153
    }
154
155
    public function getStatusAvailableAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
156
	{
157
		return ConfigStatus::type('issue')->get();
158
	}
159
160
    public function getSprintSlugAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
161
	{
162
		return isset($this->sprint->slug) ? $this->sprint->slug : 0;
0 ignored issues
show
Documentation introduced by
The property sprint does not exist on object<GitScrum\Models\Issue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
163
	}
164
165
    public function getSprintClosedAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
166
	{
167
		return isset($this->sprint->closed_at) ? $this->sprint->closed_at : null;
0 ignored issues
show
Documentation introduced by
The property sprint does not exist on object<GitScrum\Models\Issue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
168
	}
169
}
170