Completed
Pull Request — master (#30)
by Marcos
02:42
created

Issue::comments()   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
namespace GitScrum\Models;
9
10
use Illuminate\Database\Eloquent\Model;
11
use Illuminate\Database\Eloquent\SoftDeletes;
12
use Carbon\Carbon;
13
14
class Issue extends Model
15
{
16
    use SoftDeletes;
17
18
    /**
19
     * The database table used by the model.
20
     *
21
     * @var string
22
     */
23
    protected $table = 'issues';
24
25
    /**
26
     * Attributes that should be mass-assignable.
27
     *
28
     * @var array
29
     */
30
    protected $fillable = ['issue_effort_id', 'issue_type_id', 'github_id', 'user_id', 'product_backlog_id',
31
        'branch_id', 'sprint_id', 'user_story_id', 'number', 'effort', 'slug', 'code', 'title', 'description', 'state',
32
        'config_status_id', 'position', 'is_planning_poker', 'closed_user_id', 'closed_at', ];
33
34
    /**
35
     * The attributes excluded from the model's JSON form.
36
     *
37
     * @var array
38
     */
39
    protected $hidden = [];
40
41
    /**
42
     * The attributes that should be casted to native types.
43
     *
44
     * @var array
45
     */
46
    protected $casts = [];
47
48
    protected $dates = ['deleted_at'];
49
50
    protected static function boot()
51
    {
52
        parent::boot();
53
    }
54
55
    public function branch()
56
    {
57
        return $this->belongsTo(\GitScrum\Models\Branch::class, 'branch_id', 'id');
58
    }
59
60
    public function type()
61
    {
62
        return $this->belongsTo(\GitScrum\Models\IssueType::class, 'issue_type_id', 'id');
63
    }
64
65
    public function configEffort()
66
    {
67
        return $this->belongsTo(\GitScrum\Models\ConfigIssueEffort::class, 'issue_effort_id', 'id');
68
    }
69
70
    public function sprint()
71
    {
72
        return $this->belongsTo(\GitScrum\Models\Sprint::class, 'sprint_id', 'id');
73
    }
74
75
    public function productBacklog()
76
    {
77
        return $this->belongsTo(\GitScrum\Models\ProductBacklog::class, 'product_backlog_id', 'id');
78
    }
79
80
    public function userStory()
81
    {
82
        return $this->belongsTo(\GitScrum\Models\UserStory::class, 'user_story_id', 'id');
83
    }
84
85
    public function user()
86
    {
87
        return $this->belongsTo(\GitScrum\Models\User::class, 'user_id', 'id');
88
    }
89
90
    public function closedUser()
91
    {
92
        return $this->belongsTo(\GitScrum\Models\User::class, 'closed_user_id', 'id');
93
    }
94
95
    public function users()
96
    {
97
        return $this->belongsToMany(\GitScrum\Models\User::class, 'issues_has_users', 'issue_id', 'user_id')->withTimestamps();
98
    }
99
100
    public function commits()
101
    {
102
        return $this->hasMany(\GitScrum\Models\Commit::class, 'issue_id', 'id');
103
    }
104
105
    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...
106
    {
107
        return $this->morphMany(\GitScrum\Models\Comment::class, 'commentable')
108
            ->orderby('created_at', 'DESC');
109
    }
110
111
    public function attachments()
112
    {
113
        return $this->morphMany(\GitScrum\Models\Attachment::class, 'attachmentable');
114
    }
115
116
    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...
117
    {
118
        return $this->morphMany(\GitScrum\Models\Note::class, 'noteable')
119
            ->orderby('position', 'ASC');
120
    }
121
122
    public function favorite()
123
    {
124
        return $this->morphOne(\GitScrum\Models\Favorite::class, 'favoriteable');
125
    }
126
127
    public function labels()
128
    {
129
        return $this->morphToMany(\GitScrum\Models\Label::class, 'labelable');
130
    }
131
132
    public function status()
133
    {
134
        return $this->hasOne(\GitScrum\Models\ConfigStatus::class, 'id', 'config_status_id');
135
    }
136
137
    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...
138
    {
139
        return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable')
140
            ->orderby('created_at', 'DESC');
141
    }
142
143
    public function notesPercentComplete()
144
    {
145
        $total = $this->notes->count();
0 ignored issues
show
Documentation introduced by
The property notes 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...
146
        $totalClosed = $total - $this->notes->where('closed_at', null)->count();
0 ignored issues
show
Documentation introduced by
The property notes 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...
147
148
        return ($totalClosed) ? ceil(($totalClosed * 100) / $total) : 0;
149
    }
150
151
    public function dateForHumans($dateField = 'created_at')
152
    {
153
        return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes[$dateField])->diffForHumans();
154
    }
155
156
    public function setClosedUserIdAttribute($value)
157
    {
158
        $this->attributes['closed_user_id'] = $this->status->is_closed ? $value : null;
0 ignored issues
show
Documentation introduced by
The property status 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...
159
    }
160
161
    public function setClosedAtAttribute($value)
162
    {
163
        $this->attributes['closed_at'] = $this->status->is_closed ? $value : null;
0 ignored issues
show
Documentation introduced by
The property status 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...
164
    }
165
}
166