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

LanguageForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 15.22 %

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 46
rs 10

2 Methods

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