UserStory   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 109
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A productBacklog() 0 4 1
A issues() 0 5 1
A priority() 0 4 1
A favorite() 0 4 1
A comments() 0 5 1
A notes() 0 5 1
A labels() 0 4 1
A activities() 0 13 1
A issuesHasUsers() 0 10 1
A issueStatus() 0 8 1
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <renato.marinho>
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 GitScrum\Scopes\GlobalScope;
14
15
class UserStory extends Model
16
{
17
    use SoftDeletes;
18
    use GlobalScope;
19
    /**
20
     * The database table used by the model.
21
     *
22
     * @var string
23
     */
24
    protected $table = 'user_stories';
25
26
    /**
27
     * Attributes that should be mass-assignable.
28
     *
29
     * @var array
30
     */
31
    protected $fillable = ['user_id', 'product_backlog_id', 'title', 'description', 'config_priority_id', 'acceptance_criteria'];
32
33
    /**
34
     * The attributes excluded from the model's JSON form.
35
     *
36
     * @var array
37
     */
38
    protected $hidden = [];
39
40
    /**
41
     * The attributes that should be casted to native types.
42
     *
43
     * @var array
44
     */
45
    protected $casts = [];
46
47
    protected static function boot()
48
    {
49
        parent::boot();
50
    }
51
52
    public function productBacklog()
53
    {
54
        return $this->belongsTo(\GitScrum\Models\ProductBacklog::class, 'product_backlog_id', 'id');
55
    }
56
57
    public function issues()
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...
58
    {
59
        return $this->hasMany(\GitScrum\Models\Issue::class, 'user_story_id', 'id')
60
            ->orderby('position', 'ASC');
61
    }
62
63
    public function priority()
64
    {
65
        return $this->hasOne(\GitScrum\Models\ConfigPriority::class, 'id', 'config_priority_id');
66
    }
67
68
    public function favorite()
69
    {
70
        return $this->morphOne(\GitScrum\Models\Favorite::class, 'favoriteable');
71
    }
72
73
    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...
74
    {
75
        return $this->morphMany(\GitScrum\Models\Comment::class, 'commentable')
76
            ->orderby('created_at', 'DESC');
77
    }
78
79
    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...
80
    {
81
        return $this->morphMany(\GitScrum\Models\Note::class, 'noteable')
82
            ->orderby('position', 'ASC');
83
    }
84
85
    public function labels()
86
    {
87
        return $this->morphToMany(\GitScrum\Models\Label::class, 'labelable');
88
    }
89
90
    public function activities()
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...
91
    {
92
        $activities = $this->issues()
93
            ->with('statuses')->get()->map(function ($issue) {
94
                return $issue->statuses;
95
            })->flatten(1)->map(function ($statuses) {
96
                return $statuses;
97
            })->sortByDesc('created_at');
98
99
        $activities->splice(15);
100
101
        return $activities->all();
102
    }
103
104
    public function issuesHasUsers($total = 3)
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...
105
    {
106
        $users = $this->issues->map(function ($issue) {
0 ignored issues
show
Documentation introduced by
The property issues does not exist on object<GitScrum\Models\UserStory>. 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...
107
            return $issue->users;
108
        })->reject(function ($value) {
109
            return $value == null;
110
        })->flatten(1)->unique('id')->splice(0, $total);
111
112
        return $users->all();
113
    }
114
115
    public function issueStatus()
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...
116
    {
117
        $status = $this->issues->map(function ($issue) {
0 ignored issues
show
Documentation introduced by
The property issues does not exist on object<GitScrum\Models\UserStory>. 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...
118
            return $issue->status;
119
        })->groupBy('slug')->all();
120
121
        return $status;
122
    }
123
}
124