Completed
Push — develop ( 688bc1...4964b4 )
by Mohamed
07:24
created

CountTrait::createdIssuesCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 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 2
    public static function countUsers($deleted = User::NOT_DELETED_USERS)
35
    {
36 2
        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 19 View Code Duplication
    public function assignedIssuesCount($projectId = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48 19
        $issues = $this->issues();
49
50 19
        if (0 < $projectId) {
51 19
            $issues = $issues->where('project_id', '=', $projectId);
52
        }
53 19
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
54
55 19
        return $issues->count();
56
    }
57
58
    /**
59
     * Count number of created issues in a project.
60
     *
61
     * @param int $projectId
62
     *
63
     * @return int
64
     */
65 2 View Code Duplication
    public function createdIssuesCount($projectId = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67 2
        $issues = $this->issuesCreatedBy();
0 ignored issues
show
Bug introduced by
The method issuesCreatedBy() does not exist on Tinyissue\Model\Traits\User\CountTrait. Did you maybe mean issues()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
68
69 2
        if (0 < $projectId) {
70 2
            $issues = $issues->where('project_id', '=', $projectId);
71
        }
72 2
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
73
74 2
        return $issues->count();
75
    }
76
77
    /**
78
     * Returns all projects with open issue count.
79
     *
80
     * @param int $status
81
     *
82
     * @return $this
83
     */
84 3
    public function projectsWithCountOpenIssues($status = Project::STATUS_OPEN)
85
    {
86 3
        if ($this->permission('project-all')) {
87 3
            $project = new Project();
88
89 3
            return $project->projectsWithOpenIssuesCount($status, Project::PRIVATE_ALL);
90
        }
91
92
        return $this->projects($status)->with('openIssuesCount');
93
    }
94
}
95