Completed
Branch develop-3.0 (4fe777)
by Mohamed
11:06
created

CounterRepository   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 26.92 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 21
loc 78
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A countNotDeleted() 0 4 1
A countDeleted() 0 4 1
A createdIssuesCount() 11 11 2
A projectsWithCountOpenIssues() 10 10 2
A countProjectsByStatus() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Contracts\Repository\Project\ProjectRepository;
17
use Tinyissue\Contracts\Repository\User\CounterRepository as UserCounter;
18
use Tinyissue\Model\Permission;
19
use Tinyissue\Model\Project;
20
use Tinyissue\Repository\RepositoryCounter;
21
22
/**
23
 * Class CounterRepository.
24
 *
25
 * @package Tinyissue\Repository\User
26
 */
27
class CounterRepository extends RepositoryCounter implements UserCounter
28
{
29
    public function __construct(UserInterface $model)
30
    {
31
        $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...
32
    }
33
34
    /**
35
     * @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...
36
     *
37
     * @return int
38
     */
39
    public function countNotDeleted()
40
    {
41
        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...
42
    }
43
44
    /**
45
     * @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...
46
     *
47
     * @return int
48
     */
49
    public function countDeleted()
50
    {
51
        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...
52
    }
53
54
    /**
55
     * Count number of created issues in a project.
56
     *
57
     * @param int $projectId
58
     *
59
     * @return int
60
     */
61 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...
62
    {
63
        $issues = $this->issuesCreatedBy();
0 ignored issues
show
Bug introduced by
The method issuesCreatedBy() does not seem to exist on object<Tinyissue\Reposit...User\CounterRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
65
        if (0 < $projectId) {
66
            $issues = $issues->where('project_id', '=', $projectId);
67
        }
68
        $issues->where('status', '=', Project\Issue::STATUS_OPEN);
69
70
        return $issues->count();
71
    }
72
73
    /**
74
     * Returns all projects with open issue count.
75
     *
76
     * @param int $status
77
     *
78
     * @return Builder|Relations\BelongsToMany
79
     */
80 View Code Duplication
    public function projectsWithCountOpenIssues($status = Project::STATUS_OPEN)
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...
81
    {
82
        if ($this->permission('project-all')) {
0 ignored issues
show
Bug introduced by
The method permission() does not seem to exist on object<Tinyissue\Reposit...User\CounterRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
            $project = new Project();
84
85
            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 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...
86
        }
87
88
        return $this->projects($status)->with('countOpenIssues');
0 ignored issues
show
Bug introduced by
The method projects() does not exist on Tinyissue\Repository\User\CounterRepository. 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...
89
    }
90
91
    /**
92
     * Count number of archived projects.
93
     *
94
     * @return int
95
     */
96
    public function countProjectsByStatus($status)
97
    {
98
        if ($this->model->permission(Permission::PERM_PROJECT_ALL)) {
99
            return app()->make(ProjectRepository::class)->countProjectsByStatus($status);
100
        }
101
102
        return $this->model->projects()->status($status)->count();
103
    }
104
}
105