Completed
Push — develop-3.0 ( 5ab583...f20237 )
by Mohamed
06:33
created

Counter::createdIssuesCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
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\User;
13
14
use Tinyissue\Model\Project;
15
use Tinyissue\Model\User;
16
use Tinyissue\Repository\Repository;
17
18
class Counter extends Repository
19
{
20
    /**
21
     * @var User
22
     */
23
    protected $model;
24
25
    public function __construct(User $model)
26
    {
27
        $this->model = $model;
28
    }
29
30
    /**
31
     * Count active users.
32
     *
33
     * @return int
34
     */
35
    public function countNotDeleted()
36
    {
37
        return $this->model->active()->count();
38
    }
39
40
    /**
41
     * Count deleted users.
42
     *
43
     * @return int
44
     */
45
    public function countDeleted()
46
    {
47
        return $this->model->removed()->count();
48
    }
49
50
    /**
51
     * Count number of created issues in a project.
52
     *
53
     * @param int $projectId
54
     *
55
     * @return int
56
     */
57
    public function createdIssuesCount($projectId = 0)
58
    {
59
        $issues = $this->model->issuesCreatedBy();
60
61
        if (0 < $projectId) {
62
            $issues = $issues->where('project_id', '=', $projectId);
63
        }
64
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
65
66
        return $issues->count();
67
    }
68
69
    /**
70
     * Count number of archived projects.
71
     *
72
     * @param $status
73
     *
74
     * @return int
75
     */
76
    public function countProjectsByStatus($status)
77
    {
78
        if ($this->model->isManager() || $this->model->isAdmin()) {
79
            return app()->make(Project::class)->countProjectsByStatus($status);
80
        }
81
82
        return $this->model->projects()->status($status)->count();
83
    }
84
}
85