Completed
Branch develop-3.0 (132dbd)
by Mohamed
03:28
created

Counter::countClosedIssues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 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;
13
14
use Tinyissue\Contracts\Model\UserInterface;
15
use Tinyissue\Model\Project;
16
use Tinyissue\Repository\Repository;
17
18
class Counter extends Repository
19
{
20
    public function __construct(Project $model)
21
    {
22
        $this->model = $model;
23
    }
24
25
    /**
26
     * Count number of open issue in the project.
27
     *
28
     * @param UserInterface|null $limitByUser
29
     *
30
     * @return int
31
     */
32
    public function countOpenIssues(UserInterface $limitByUser = null)
33
    {
34
        return $this->model->openIssues()->limitByCreatedForInternalProject($this->model, $limitByUser)->count();
35
    }
36
37
    /**
38
     * Count number of closed issue in the project.
39
     *
40
     * @param UserInterface|null $limitByUser
41
     *
42
     * @return int
43
     */
44
    public function countClosedIssues(UserInterface $limitByUser = null)
45
    {
46
        return $this->model
47
            ->closedIssues()
48
            ->limitByCreatedForInternalProject($this->model, $limitByUser)
49
            ->count();
50
    }
51
52
    /**
53
     * Count notes in project.
54
     *
55
     * @return int
56
     */
57
    public function countNotes()
58
    {
59
        return $this->model->notes()->count();
60
    }
61
62
    /**
63
     * Count number of assigned issues in a project.
64
     *
65
     * @param UserInterface $forUser
66
     *
67
     * @return int
68
     */
69
    public function countAssignedIssues(UserInterface $forUser)
70
    {
71
        return $this->model->openIssues()->assignedTo($forUser)->count();
72
    }
73
74
    /**
75
     * Count number of created issues in a project.
76
     *
77
     * @param UserInterface $forUser
78
     *
79
     * @return int
80
     */
81
    public function countCreatedIssues(UserInterface $forUser)
82
    {
83
        return $this->model->openIssues()->createdBy($forUser)->count();
84
    }
85
86
    /**
87
     * Count number of private projects.
88
     *
89
     * @return int
90
     */
91
    public function countPrivateProjects()
92
    {
93
        return $this->model->notPublic()->count();
94
    }
95
96
    /**
97
     * Count number of open projects.
98
     *
99
     * @return int
100
     */
101
    public function countActiveProjects()
102
    {
103
        return $this->model->active()->count();
104
    }
105
106
    /**
107
     * Count number of archived projects.
108
     *
109
     * @return int
110
     */
111
    public function countArchivedProjects()
112
    {
113
        return $this->model->archived()->count();
114
    }
115
116
    /**
117
     * Count number of archived projects.
118
     *
119
     * @param $status
120
     *
121
     * @return int
122
     */
123
    public function countProjectsByStatus($status)
124
    {
125
        if ($status === Project::STATUS_OPEN) {
126
            return $this->countActiveProjects();
127
        }
128
129
        return $this->countArchivedProjects();
130
    }
131
}
132