Completed
Branch develop-3.0 (103ce4)
by Mohamed
03:09
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 Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Contracts\Model\UserInterface;
16
use Tinyissue\Model\Project;
17
use Tinyissue\Repository\Repository;
18
19
class Counter extends Repository
20
{
21
    public function __construct(UserInterface $model)
22
    {
23
        $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<Illuminate\Database\Eloquent\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...
24
    }
25
26
    /**
27
     * Count active users.
28
     *
29
     * @return int
30
     */
31
    public function countNotDeleted()
32
    {
33
        return $this->model->notDeleted()->count();
0 ignored issues
show
Bug introduced by
The method notDeleted() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean delete()?

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...
34
    }
35
36
    /**
37
     * Count deleted users.
38
     *
39
     * @return int
40
     */
41
    public function countDeleted()
42
    {
43
        return $this->model->deleted()->count();
0 ignored issues
show
Bug introduced by
The call to deleted() misses a required argument $callback.

This check looks for function calls that miss required arguments.

Loading history...
Bug introduced by
The method count cannot be called on $this->model->deleted() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
44
    }
45
46
    /**
47
     * Count number of created issues in a project.
48
     *
49
     * @param int $projectId
50
     *
51
     * @return int
52
     */
53
    public function createdIssuesCount($projectId = 0)
54
    {
55
        $issues = $this->model->issuesCreatedBy();
0 ignored issues
show
Bug introduced by
The method issuesCreatedBy() does not exist on Illuminate\Database\Eloquent\Model. Did you maybe mean create()?

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...
56
57
        if (0 < $projectId) {
58
            $issues = $issues->where('project_id', '=', $projectId);
59
        }
60
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
61
62
        return $issues->count();
63
    }
64
65
    /**
66
     * Count number of archived projects.
67
     *
68
     * @param $status
69
     *
70
     * @return int
71
     */
72
    public function countProjectsByStatus($status)
73
    {
74 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...
75
            return app()->make(Project::class)->countProjectsByStatus($status);
76
        }
77
78
        return $this->model->projects()->status($status)->count();
79
    }
80
}
81