Completed
Push — develop-3.0 ( bd5ff0...545efb )
by Mohamed
02:33
created

Fetcher   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 100
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getByNumber() 0 4 1
A getStatusTag() 0 4 1
A getTypeTag() 0 4 1
A getResolutionTag() 0 4 1
A getGeneralActivities() 0 11 1
A getCommentActivities() 0 16 1
A tagOfType() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Repository\Project\Issue;
13
14
use Illuminate\Database\Eloquent\Collection;
15
use Tinyissue\Model\Project;
16
use Tinyissue\Model\Tag;
17
use Tinyissue\Model\User\Activity as UserActivity;
18
use Tinyissue\Repository\Repository;
19
20
class Fetcher extends Repository
21
{
22
    /**
23
     * @var Project\Issue
24
     */
25
    protected $model;
26
27
    public function __construct(Project\Issue $model)
28
    {
29
        $this->model = $model;
30
    }
31
32
    public function getByNumber($number)
0 ignored issues
show
Unused Code introduced by
The parameter $number is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
35
    }
36
37
    /**
38
     * Returns the status tag.
39
     *
40
     * @return Tag
41
     */
42
    public function getStatusTag()
43
    {
44
        return $this->tagOfType(Tag::GROUP_STATUS);
45
    }
46
47
    /**
48
     * Returns the type tag.
49
     *
50
     * @return Tag
51
     */
52
    public function getTypeTag()
53
    {
54
        return $this->tagOfType(Tag::GROUP_TYPE);
55
    }
56
57
    /**
58
     * Returns the resolution tag.
59
     *
60
     * @return Tag
61
     */
62
    public function getResolutionTag()
63
    {
64
        return $this->tagOfType(Tag::GROUP_RESOLUTION);
65
    }
66
67
    /**
68
     * Get collection of issue activities.
69
     *
70
     * @return Collection
71
     */
72
    public function getGeneralActivities()
73
    {
74
        $activities = $this->model->generalActivities()->get();
75
76
        $activities->each(function (UserActivity $activity) {
77
            $activity->setRelation('issue', $this->model);
78
            $activity->setRelation('project', $this->model->project);
79
        });
80
81
        return $activities;
82
    }
83
84
    /**
85
     * Get collection of issue comments.
86
     *
87
     * @return Collection
88
     */
89
    public function getCommentActivities()
90
    {
91
        $this->model->setRelation('attachments.issue', $this->model);
92
        $this->model->attachments->each(function (Project\Issue\Attachment $attachment) {
93
            $attachment->setRelation('issue', $this->model);
94
        });
95
96
        $activities = $this->model->commentActivities()->get();
97
98
        $activities->each(function (UserActivity $activity) {
99
            $activity->setRelation('issue', $this->model);
100
            $activity->setRelation('project', $this->model->project);
101
        });
102
103
        return $activities;
104
    }
105
106
    /**
107
     * Return tag by it group name.
108
     *
109
     * @param string $group
110
     *
111
     * @return Tag
112
     */
113
    protected function tagOfType($group)
114
    {
115
        return $this->model->tags
116
            ->where('parent.name', $group)
117
            ->first();
118
    }
119
}
120