Completed
Push — develop-3.0 ( 4fe777...24fc5d )
by Mohamed
09:15
created

Fetcher   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 81
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getStatusTag() 0 4 1
A getTypeTag() 0 4 1
A getResolutionTag() 0 4 1
A tagOfType() 0 6 1
A getGeneralActivities() 0 11 1
A getCommentActivities() 0 17 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 Tinyissue\Model\Project;
15
use Tinyissue\Model\Tag;
16
use Tinyissue\Repository\Repository;
17
use Tinyissue\Model\User\Activity as UserActivity;
18
19
class Fetcher extends Repository
20
{
21
    public function __construct(Project\Issue $model)
22
    {
23
        $this->model = $model;
0 ignored issues
show
Documentation Bug introduced by
It seems like $model of type object<Tinyissue\Model\Project\Issue> is incompatible with the declared type object<Tinyissue\Repository\Model> of property $model.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
    }
25
26
    /**
27
     * Returns the status tag.
28
     *
29
     * @return Tag
30
     */
31
    public function getStatusTag()
32
    {
33
        return $this->tagOfType(Tag::GROUP_STATUS);
34
    }
35
36
    /**
37
     * Returns the type tag.
38
     *
39
     * @return Tag
40
     */
41
    public function getTypeTag()
42
    {
43
        return $this->tagOfType(Tag::GROUP_TYPE);
44
    }
45
46
    /**
47
     * Returns the resolution tag.
48
     *
49
     * @return Tag
50
     */
51
    public function getResolutionTag()
52
    {
53
        return $this->tagOfType(Tag::GROUP_RESOLUTION);
54
    }
55
56
    /**
57
     * Return tag by it group name.
58
     *
59
     * @param string $group
60
     *
61
     * @return Tag
62
     */
63
    protected function tagOfType($group)
64
    {
65
        return $this->model->tags
66
            ->where('parent.name', $group)
67
            ->first();
68
    }
69
70
    public function getGeneralActivities()
71
    {
72
        $activities = $this->model->generalActivities()->get();
73
74
        $activities->each(function (UserActivity $activity) {
75
            $activity->setRelation('issue', $this->model);
76
            $activity->setRelation('project', $this->model->project);
77
        });
78
79
        return $activities;
80
    }
81
82
    public function getCommentActivities()
83
    {
84
        // @todo test if we need this
85
        //        $issue->setRelation('attachments.issue', $issue);
86
        $this->model->attachments->each(function (Attachment $attachment) {
87
            $attachment->setRelation('issue', $this->model);
88
        });
89
90
        $activities = $this->model->commentActivities()->get();
91
92
        $activities->each(function (UserActivity $activity) {
93
            $activity->setRelation('issue', $this->model);
94
            $activity->setRelation('project', $this->model->project);
95
        });
96
97
        return $activities;
98
    }
99
}
100