Sprint::totalPullRequests()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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
use GitScrum\Scopes\SprintScope;
16
17
class Sprint extends Model
18
{
19
    use SoftDeletes;
20
    use SprintScope;
21
    use GlobalScope;
22
23
    /**
24
     * The database table used by the model.
25
     *
26
     * @var string
27
     */
28
    protected $table = 'sprints';
29
30
    /**
31
     * Attributes that should be mass-assignable.
32
     *
33
     * @var array
34
     */
35
    protected $fillable = ['user_id', 'product_backlog_id', 'slug', 'title', 'description', 'version',
36
        'is_private', 'date_start', 'date_finish', 'state', 'color', 'position', 'closed_at', ];
37
38
    /**
39
     * The attributes excluded from the model's JSON form.
40
     *
41
     * @var array
42
     */
43
    protected $hidden = [];
44
45
    /**
46
     * The attributes that should be casted to native types.
47
     *
48
     * @var array
49
     */
50
    protected $casts = [];
51
52
    protected static function boot()
53
    {
54
        parent::boot();
55
    }
56
57
    public function productBacklog()
58
    {
59
        return $this->belongsTo(\GitScrum\Models\ProductBacklog::class, 'product_backlog_id', 'id');
60
    }
61
62
    public function branches()
63
    {
64
        return $this->hasMany(\GitScrum\Models\Branch::class, 'sprint_id', 'id');
65
    }
66
67
    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...
68
    {
69
        return $this->hasMany(\GitScrum\Models\Issue::class, 'sprint_id', 'id')
70
            ->orderby('position', 'ASC');
71
    }
72
73
    public function issuesHasUsers()
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
        $users = $this->issues->map(function ($issue) {
0 ignored issues
show
Documentation introduced by
The property issues does not exist on object<GitScrum\Models\Sprint>. 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...
76
            return $issue->users;
77
        })->reject(function ($value) {
78
            return $value == null;
79
        })->flatten(1)->unique('id')->splice(0, 3);
80
81
        return $users->all();
82
    }
83
84
    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...
85
    {
86
        return $this->morphMany(\GitScrum\Models\Comment::class, 'commentable')
87
            ->orderby('created_at', 'DESC');
88
    }
89
90
    public function attachments()
91
    {
92
        return $this->morphMany(\GitScrum\Models\Attachment::class, 'attachmentable');
93
    }
94
95
    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...
96
    {
97
        return $this->morphMany(\GitScrum\Models\Note::class, 'noteable')
98
            ->orderby('position', 'ASC');
99
    }
100
101
    public function favorite()
102
    {
103
        return $this->morphOne(\GitScrum\Models\Favorite::class, 'favoriteable');
104
    }
105
106
    public function status()
107
    {
108
        return $this->hasOne(\GitScrum\Models\ConfigStatus::class, 'id', 'config_status_id');
109
    }
110
111
    public function pullrequests()
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...
112
    {
113
        $prs = $this->branches->map(function ($branch) {
0 ignored issues
show
Documentation introduced by
The property branches does not exist on object<GitScrum\Models\Sprint>. 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...
114
            if ($branch->pullrequests->count()) {
115
                return $branch->pullrequests;
116
            }
117
        })->reject(function ($value) {
118
            return $value == null;
119
        });
120
121
        return $prs->all();
122
    }
123
124
    public function totalAdditions()
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...
125
    {
126
        $additions = $this->branches->map(function ($branch) {
0 ignored issues
show
Documentation introduced by
The property branches does not exist on object<GitScrum\Models\Sprint>. 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...
127
            return $branch->commits;
128
        })->flatten(1)->map(function ($commit) {
129
            return $commit->files;
130
        })->flatten(1)->sum('additions');
131
132
        return $additions;
133
    }
134
135
    public function totalPullRequests()
136
    {
137
        $prs = $this->branches->map(function ($branch) {
0 ignored issues
show
Documentation introduced by
The property branches does not exist on object<GitScrum\Models\Sprint>. 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...
138
            return $branch->pullrequests()->count();
139
        });
140
141
        return array_sum($prs->all());
142
    }
143
144
    public function workingDays($start = null)
145
    {
146
        $begin = strtotime(is_null($start) ? $this->attributes['date_start'] : $start);
147
        $end = strtotime($this->attributes['date_finish']);
148
        if ($begin > $end) {
149
            return 0;
150
        } else {
151
            $no_days = 0;
152
            $weekends = 0;
153
            while ($begin <= $end) {
154
                ++$no_days;
155
                $what_day = date('N', $begin);
156
                if ($what_day > 5) {
157
                    ++$weekends;
158
                }
159
                $begin += 86400;
160
            }
161
            $working_days = $no_days - $weekends;
162
163
            return $working_days;
164
        }
165
    }
166
167
    public function weeks($start = null)
168
    {
169
        $begin = Carbon::parse(is_null($start) ? $this->attributes['date_start'] : $start);
170
        $end = Carbon::parse($this->attributes['date_finish']);
171
172
        return round($begin->diffInDays($end) / 7);
173
    }
174
175
    public function getPSR2Errors()
176
    {
177
        $errors = 0;
178
        /*
179
        foreach ($this->branches as $branch) {
180
            foreach ($branch->commits as $commit) {
181
                foreach ($commit->files as $file) {
182
                    $errors += $file->filePhpcs->count();
183
                }
184
            }
185
        }
186
        */
187
        return $errors;
188
    }
189
190
    public function getEffort()
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...
191
    {
192
        $effort = $this->issues->map(function ($issue) {
0 ignored issues
show
Documentation introduced by
The property issues does not exist on object<GitScrum\Models\Sprint>. 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...
193
            return $issue->configEffort;
194
        })->sum('effort');
195
196
        return $effort;
197
    }
198
199
    public function getEffortAvg()
200
    {
201
        $effort = $this->issues->map(function ($issue) {
0 ignored issues
show
Documentation introduced by
The property issues does not exist on object<GitScrum\Models\Sprint>. 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...
202
            return $issue->configEffort;
203
        })->avg('effort');
204
205
        return round($effort, 2);
206
    }
207
208
    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...
209
    {
210
        $activities = $this->issues()
211
            ->with('statuses')->get()->map(function ($issue) {
212
                return $issue->statuses;
213
            })->flatten(1)->map(function ($statuses) {
214
                return $statuses;
215
            })->sortByDesc('created_at');
216
217
        $activities->splice(15);
218
219
        return $activities->all();
220
    }
221
222
    public function issueTypes()
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...
223
    {
224
        $types = $this->issues->map(function ($issue) {
0 ignored issues
show
Documentation introduced by
The property issues does not exist on object<GitScrum\Models\Sprint>. 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...
225
            return $issue->type;
226
        })->groupBy('slug')->map(function ($type) {
227
            return [
228
                'sprint' => $this->slug,
0 ignored issues
show
Documentation introduced by
The property slug does not exist on object<GitScrum\Models\Sprint>. 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...
229
                'slug' => $type->first()->slug,
230
                'title' => $type->first()->title,
231
                'color' => $type->first()->color,
232
                'total' => $type->count(), ];
233
        })->sortByDesc('total')->all();
234
235
        return $types;
236
    }
237
238
    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...
239
    {
240
        $status = $this->issues->map(function ($issue) {
0 ignored issues
show
Documentation introduced by
The property issues does not exist on object<GitScrum\Models\Sprint>. 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...
241
            return $issue->status;
242
        })->groupBy('slug')->all();
243
244
        return $status;
245
    }
246
247
    public function getVisibilityAttribute()
248
    {
249
        return $this->attributes['is_private'] ? trans('Private') : trans('Public');
250
    }
251
252
    public function getSlugAttribute()
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...
253
    {
254
        return isset($this->attributes['slug']) ? $this->attributes['slug'] : '';
255
    }
256
257
    public function getTimeboxAttribute()
258
    {
259
        $date_start = isset($this->attributes['date_start']) ?
260
            Carbon::parse($this->attributes['date_start'])->toDateString() : '';
261
        $date_finish = isset($this->attributes['date_finish']) ?
262
            Carbon::parse($this->attributes['date_finish'])->toDateString() : '';
263
264
        return $date_start.' '.trans('to').' '.$date_finish;
265
    }
266
}
267