FilterIssue   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 130
Duplicated Lines 6.15 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 7
c 3
b 1
f 1
lcom 1
cbo 5
dl 8
loc 130
ccs 40
cts 40
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRedirectUrl() 0 4 1
A setup() 0 4 1
A openType() 0 4 1
A actions() 0 10 1
A fields() 0 56 1
A getTags() 8 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\Form;
13
14
use Request;
15
use Tinyissue\Model;
16
17
/**
18
 * FilterIssue is a class to defines fields & rules for issue filter form.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 */
22
class FilterIssue extends FormAbstract
23
{
24
    /**
25
     * An instance of project model.
26
     *
27
     * @var Model\Project
28
     */
29
    protected $project;
30
31
    /**
32
     * Collection of all tags.
33
     *
34
     * @var \Illuminate\Database\Eloquent\Collection
35
     */
36
    protected $tags = null;
37
38
    /**
39
     * @param string $type
40
     *
41
     * @return \Illuminate\Database\Eloquent\Collection|null
42
     */
43 30 View Code Duplication
    protected function getTags($type)
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...
44
    {
45 30
        if ($this->tags === null) {
46 30
            $this->tags = (new Model\Tag())->getGroupTags();
47
        }
48
49 30
        return $this->tags->where('name', $type)->first()->tags;
50
    }
51
52
    /**
53
     * @param array $params
54
     *
55
     * @return void
56
     */
57 36
    public function setup(array $params)
58
    {
59 36
        $this->project = $params['project'];
60 36
    }
61
62
    /**
63
     * @return array
64
     */
65 2
    public function actions()
66
    {
67
        return [
68
            'filter' => [
69
                'name'  => 'filter',
70
                'label' => 'filter',
71
                'type'  => 'info_submit',
72 2
            ],
73
        ];
74
    }
75
76
    /**
77
     * @return array
78
     */
79 30
    public function fields()
80
    {
81
        // Prefix tag groups with "tag:"
82 30
        $tagGroups = (new Model\Tag())->groupsDropdown();
83
84
        // Array of sort optins
85 30
        $sort = ['updated' => trans('tinyissue.updated')] + $tagGroups;
86
87
        // Array of project users
88 30
        $assignTo = [0 => trans('tinyissue.allusers')] + $this->project->users()->get()->lists('fullname', 'id')->all();
89
90
        $fields = [
91
            'keyword' => [
92 30
                'type'            => 'text',
93 30
                'placeholder'     => trans('tinyissue.keywords'),
94 30
                'onGroupAddClass' => 'toolbar-item first',
95
            ],
96
            'tag_status' => [
97 30
                'type'            => 'select',
98 30
                'placeholder'     => trans('tinyissue.status'),
99 30
                'onGroupAddClass' => 'toolbar-item',
100 30
                'options'         => $this->getTags('status')->lists('fullname', 'id'),
101
            ],
102
            'tag_type' => [
103 30
                'type'            => 'select',
104 30
                'placeholder'     => trans('tinyissue.type'),
105 30
                'onGroupAddClass' => 'toolbar-item',
106 30
                'options'         => $this->getTags('type')->lists('fullname', 'id'),
107
            ],
108
            'sort' => [
109 30
                'type'            => 'groupField',
110 30
                'onGroupAddClass' => 'toolbar-item',
111
                'fields'          => [
112
                    'sortby' => [
113 30
                        'type'         => 'select',
114 30
                        'placeholder'  => trans('tinyissue.sortby'),
115 30
                        'options'      => $sort,
116 30
                        'onGroupClass' => 'control-inline control-sortby',
117
                    ],
118
                    'sortorder' => [
119 30
                        'type'         => 'select',
120 30
                        'options'      => ['asc' => trans('tinyissue.sort_asc'), 'desc' => trans('tinyissue.sort_desc')],
121 30
                        'onGroupClass' => 'control-inline control-sortorder',
122
                    ],
123
                ],
124
            ],
125
            'assignto' => [
126 30
                'type'            => 'select',
127 30
                'placeholder'     => trans('tinyissue.assigned_to'),
128 30
                'options'         => $assignTo,
129 30
                'onGroupAddClass' => 'toolbar-item last',
130
            ],
131
        ];
132
133 30
        return $fields;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getRedirectUrl()
140
    {
141
        return $this->project->to();
142
    }
143
144
    /**
145
     * @return string
146
     */
147 2
    public function openType()
148
    {
149 2
        return 'inline_open';
150
    }
151
}
152