Completed
Branch develop (a31570)
by Mohamed
08:09 queued 04:45
created

CountTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 92.31%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 48
ccs 12
cts 13
cp 0.9231
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A countUsers() 0 4 1
A assignedIssuesCount() 0 11 2
A projectsWithCountOpenIssues() 0 9 2
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\Model\Traits\User;
13
14
use Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Model\Project;
16
use Tinyissue\Model\User;
17
18
/**
19
 * CountTrait is trait class containing the methods for counting database records for the User model
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 *
23
 * @method bool              permission($key)
24
 * @method Relations\HasMany projects($status = Project::STATUS_OPEN)
25
 * @method Relations\HasMany issues()
26
 */
27
trait CountTrait
28
{
29
    /**
30
     * @param int $deleted
31
     *
32
     * @return int
33
     */
34 1
    public static function countUsers($deleted = User::NOT_DELETED_USERS)
35
    {
36 1
        return User::where('deleted', '=', $deleted)->count();
37
    }
38
39
    /**
40
     * Count number of assigned issues in a project
41
     *
42
     * @param int $projectId
43
     *
44
     * @return int
45
     */
46 18
    public function assignedIssuesCount($projectId = 0)
47
    {
48 18
        $issues = $this->issues();
49
50 18
        if (0 < $projectId) {
51 18
            $issues = $issues->where('project_id', '=', $projectId);
52
        }
53 18
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
54
55 18
        return $issues->count();
56
    }
57
58
    /**
59
     * Returns all projects with open issue count
60
     *
61
     * @param int $status
62
     *
63
     * @return $this
64
     */
65 3
    public function projectsWithCountOpenIssues($status = Project::STATUS_OPEN)
66
    {
67 3
        if ($this->permission('project-all')) {
68 3
            $project = new Project();
69 3
            return $project->projectsWithOpenIssuesCount($status, Project::PRIVATE_ALL);
70
        }
71
72
        return $this->projects($status)->with('openIssuesCount');
73
    }
74
}
75