CountTrait::projectsWithCountOpenIssues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.032
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\Builder;
15
use Illuminate\Database\Eloquent\Relations;
16
use Tinyissue\Model\Project;
17
use Tinyissue\Model\User;
18
19
/**
20
 * CountTrait is trait class containing the methods for counting database records for the User model.
21
 *
22
 * @author Mohamed Alsharaf <[email protected]>
23
 *
24
 * @property static $this
25
 */
26
trait CountTrait
27
{
28
    /**
29
     * @param int $deleted
30
     *
31
     * @return int
32
     */
33 2
    public static function countUsers($deleted = User::NOT_DELETED_USERS)
34
    {
35 2
        return User::where('deleted', '=', $deleted)->count();
36
    }
37
38
    /**
39
     * Count number of assigned issues in a project.
40
     *
41
     * @param int $projectId
42
     *
43
     * @return int
44
     */
45 20
    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...
46
    {
47 20
        $issues = $this->issues();
0 ignored issues
show
Bug introduced by
The method issues() does not exist on Tinyissue\Model\Traits\User\CountTrait. Did you maybe mean assignedIssuesCount()?

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...
48
49 20
        if (0 < $projectId) {
50 20
            $issues = $issues->where('project_id', '=', $projectId);
51
        }
52 20
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
53
54 20
        return $issues->count();
55
    }
56
57
    /**
58
     * Count number of created issues in a project.
59
     *
60
     * @param int $projectId
61
     *
62
     * @return int
63
     */
64 2
    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...
65
    {
66 2
        $issues = $this->issuesCreatedBy();
67
68 2
        if (0 < $projectId) {
69 2
            $issues = $issues->where('project_id', '=', $projectId);
70
        }
71 2
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
72
73 2
        return $issues->count();
74
    }
75
76
    /**
77
     * Returns all projects with open issue count.
78
     *
79
     * @param int $status
80
     *
81
     * @return Builder|Relations\BelongsToMany
82
     */
83 3
    public function projectsWithCountOpenIssues($status = Project::STATUS_OPEN)
84
    {
85 3
        if ($this->permission('project-all')) {
86 3
            $project = new Project();
87
88 3
            return $project->projectsWithOpenIssuesCount($status, Project::PRIVATE_ALL);
89
        }
90
91
        return $this->projects($status)->with('openIssuesCount');
0 ignored issues
show
Bug introduced by
The method projects() does not exist on Tinyissue\Model\Traits\User\CountTrait. Did you maybe mean projectsWithCountOpenIssues()?

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...
92
    }
93
94
    abstract public function issuesCreatedBy();
95
96
    abstract public function permission($key);
97
}
98