FilterIssue::fields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 56
ccs 29
cts 29
cp 1
rs 9.7251
cc 1
eloc 38
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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