Tag   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 2
Metric Value
wmc 9
c 7
b 0
f 2
lcom 1
cbo 4
dl 0
loc 97
ccs 32
cts 32
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 6 2
A actions() 0 6 2
A getRedirectUrl() 0 8 2
A rules() 0 13 2
B fields() 0 40 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\Form;
13
14
use Tinyissue\Model;
15
use Tinyissue\Model\Role;
16
17
/**
18
 * Tag is a class to defines fields & rules for add/edit tag form.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 */
22
class Tag extends FormAbstract
23
{
24
    /**
25
     * @param array $params
26
     *
27
     * @return void
28
     */
29 2
    public function setup(array $params)
30
    {
31 2
        if (isset($params['tag'])) {
32 1
            $this->editingModel($params['tag']);
33
        }
34 2
    }
35
36
    /**
37
     * @return array
38
     */
39 2
    public function actions()
40
    {
41
        return [
42 2
            'submit' => $this->isEditing() ? 'update_tag' : 'create_tag',
43
        ];
44
    }
45
46
    /**
47
     * @return array
48
     */
49 2
    public function fields()
50
    {
51 2
        $roles  = Role::dropdown()->prepend('Disabled');
52 2
        $tag    = new Model\Tag();
53
        $fields = [
54
            'name' => [
55
                'type'  => 'text',
56
                'label' => 'name',
57 2
            ],
58
            'parent_id' => [
59 2
                'type'    => 'select',
60 2
                'label'   => 'group',
61 2
                'options' => $tag->getGroups()->lists('name', 'id')->all(),
62
            ],
63
            'bgcolor' => [
64
                'type'  => 'color',
65
                'label' => 'bgcolor',
66
            ],
67
            'role_limit' => [
68 2
                'type'    => 'select',
69 2
                'label'   => 'limit_access',
70 2
                'options' => $roles,
71 2
                'help'    => trans('tinyissue.role_limit_help'),
72
            ],
73
            'message_limit' => [
74 2
                'type'    => 'select',
75 2
                'label'   => 'limit_message',
76 2
                'options' => $roles,
77 2
                'help'    => trans('tinyissue.limit_message_help'),
78
            ],
79
            'readonly' => [
80 2
                'type'    => 'select',
81 2
                'label'   => 'readonly',
82 2
                'options' => $roles,
83 2
                'help'    => trans('tinyissue.readonly_tag_help'),
84
            ],
85
        ];
86
87 2
        return $fields;
88
    }
89
90
    /**
91
     * @return array
92
     */
93 2
    public function rules()
94
    {
95
        // Tag to exclude in unique test while editing
96 2
        $excludeTag = $this->isEditing() ? ',' . $this->getModel()->id : '';
97
98
        $rules = [
99 2
            'name'      => 'required|max:200|unique:tags,name' . $excludeTag,
100 2
            'parent_id' => 'required',
101 2
            'bgcolor'   => 'required',
102
        ];
103
104 2
        return $rules;
105
    }
106
107
    /**
108
     * @return mixed
109
     */
110
    public function getRedirectUrl()
111
    {
112
        if ($this->isEditing()) {
113
            return $this->getModel()->to('edit');
114
        }
115
116
        return (new Model\Tag())->to('new');
117
    }
118
}
119