Completed
Push — develop-3.0 ( 4fe777...24fc5d )
by Mohamed
09:15
created

Counter::countNotDeleted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Contracts\Model\UserInterface;
16
use Tinyissue\Model\Permission;
17
use Tinyissue\Model\Project;
18
use Tinyissue\Repository\Repository;
19
20
/**
21
 * Class Counter.
22
 *
23
 * @package Tinyissue\\User
24
 */
25
class Counter extends Repository
26
{
27
    public function __construct(UserInterface $model)
28
    {
29
        $this->model = $model;
0 ignored issues
show
Documentation Bug introduced by
It seems like $model of type object<Tinyissue\Contracts\Model\UserInterface> is incompatible with the declared type object<Tinyissue\Repository\Model> of property $model.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
    }
31
32
    /**
33
     * @param int $deleted
0 ignored issues
show
Bug introduced by
There is no parameter named $deleted. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
34
     *
35
     * @return int
36
     */
37
    public function countNotDeleted()
38
    {
39
        return $this->model->notDeleted()->count();
40
    }
41
42
    /**
43
     * @param int $deleted
0 ignored issues
show
Bug introduced by
There is no parameter named $deleted. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

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

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...
85
        }
86
87
        return $this->model->projects($status)->with('openIssuesCount');
88
    }
89
90
    /**
91
     * Count number of archived projects.
92
     *
93
     * @return int
94
     */
95
    public function countProjectsByStatus($status)
96
    {
97 View Code Duplication
        if ($this->model->isManager() || $this->model->isAdmin()) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
98
            return app()->make(Project::class)->countProjectsByStatus($status);
99
        }
100
101
        return $this->model->projects()->status($status)->count();
102
    }
103
}
104