Completed
Push — master ( ab5ce3...f55930 )
by Helmut
02:51
created

Name   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 66
Duplicated Lines 6.06 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 16
c 3
b 0
f 1
lcom 1
cbo 3
dl 4
loc 66
ccs 36
cts 36
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 8 1
A getButtonName() 0 4 1
A renderWith() 0 9 1
A setValueFromDefault() 0 6 3
A setValueFromModel() 2 6 3
A setValueFromRequest() 0 6 1
A fillModelWithValue() 2 6 4
A validateRequired() 0 5 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
namespace Helmut\Forms\Fields\Name;
4
5
use Helmut\Forms\Field;
6
use Helmut\Forms\Utility\Validate;
7
8
class Name extends Field {
9
10
    public $default = [];
11
    public $value_first = '';
12
    public $value_surname = '';
13 12
    public $value = '';
14
15 12
    public function getValue() 
16 12
    {
17 12
        $values = [];
18 12
        $values[$this->name.'_first'] = $this->value_first;
19 12
        $values[$this->name.'_surname'] = $this->value_surname;
20
        $values[$this->name] = $this->value;
21
        return $values;
22 14
    }
23
24 14
    public function getButtonName()
25
    {
26
        //
27 4
    }
28
29 4
    public function renderWith() 
30 4
    {
31 4
        return [    
32 4
            'name_first' => $this->name.'_first', 
33
            'name_surname' => $this->name.'_surname', 
34
            'value_first' => $this->value_first, 
35
            'value_surname' => $this->value_surname,
36 13
        ];
37
    }    
38 13
39 13
    public function setValueFromDefault()
40 13
    {
41 13
        if (isset($this->default['first'])) $this->value_first = $this->default['first'];
42
        if (isset($this->default['surname'])) $this->value_surname = $this->default['surname'];
43 1
        $this->value = trim($this->value_first.' '.$this->value_surname);
44
    }
45 1
46 1
    public function setValueFromModel($model)
47 1
    {
48 1 View Code Duplication
        if (property_exists($model, $this->name.'_first')) $this->value_first = $model->{$this->name.'_first'};
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
49 View Code Duplication
        if (property_exists($model, $this->name.'_surname')) $this->value_surname = $model->{$this->name.'_surname'};
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
50 2
        $this->value = trim($this->value_first.' '.$this->value_surname);
51
    }
52 2
53 2
    public function setValueFromRequest($request)
54 2
    {
55 2
        $this->value_first = $request->get($this->name.'_first');
56
        $this->value_surname = $request->get($this->name.'_surname');
57 1
        $this->value = trim($this->value_first.' '.$this->value_surname);
58
    }
59 1
60 1
    public function fillModelWithValue($model)
61 1
    {
62 1 View Code Duplication
        if (property_exists($model, $this->name.'_first')) $model->{$this->name.'_first'} = $this->value_first;
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
63 View Code Duplication
        if (property_exists($model, $this->name.'_surname')) $model->{$this->name.'_surname'} = $this->value_surname;
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
64 1
        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
65
    }
66 1
67 1
    public function validateRequired()
68
    {
69
        return Validate::required($this->value_first)
70
                && Validate::required($this->value_surname);
71
    }   
72
73
}
74