Completed
Push — master ( 188ffb...31684b )
by Maxime
02:48
created

RoleForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 15.91 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 3
dl 7
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildForm() 0 21 1
A getUpdateRules() 7 7 1

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 namespace Distilleries\Expendable\Http\Forms\Role;
2
3
use Distilleries\Expendable\Helpers\StaticLabel;
4
use Distilleries\FormBuilder\FormValidator;
5
6
class RoleForm extends FormValidator {
7
8
    public static $rules = [
9
        'libelle'            => 'required',
10
        'initials'           => 'required|unique:roles',
11
        'overide_permission' => 'integer'
12
    ];
13
14
    public static $rules_update = [
15
        'libelle'            => 'required',
16
        'initials'           => 'required|unique:roles,initials',
17
        'overide_permission' => 'integer'
18
    ];
19
20
    public function buildForm()
21
    {
22
        $this
23
            ->add('id', 'hidden')
24
            ->add('libelle', 'text', [
25
                'validation' => 'required',
26
                'label'      => trans('expendable::form.libelle')
27
            ])
28
            ->add('initials', 'text', [
29
                'validation' => 'required',
30
                'label'      => trans('expendable::form.initials')
31
            ])
32
            ->add('overide_permission', 'choice', [
33
                'choices'     => StaticLabel::yesNo(),
34
                'empty_value' => '-',
35
                'validation'  => 'required',
36
                'label'       => trans('expendable::form.allow_automatically_all_permission')
37
            ]);
38
39
        $this->addDefaultActions();
40
    }
41
42 View Code Duplication
    protected function getUpdateRules()
43
    {
44
        $key                           = \Request::get($this->model->getKeyName());
45
        static::$rules_update['initials'] = 'required|unique:roles,initials' . $key;
46
47
        return parent::getUpdateRules();
48
    }
49
}