Completed
Push — master ( 72a246...6ab249 )
by Helmut
05:19
created

Search   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 45
loc 45
c 0
b 0
f 0
wmc 10
lcom 1
cbo 3
rs 10
ccs 9
cts 9
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 4 4 1
A getButtonName() 4 4 1
A renderWith() 4 4 1
A setValueFromDefault() 4 4 1
A setValueFromModel() 4 4 2
A setValueFromRequest() 4 4 1
A fillModelWithValue() 4 4 2
A validateRequired() 4 4 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 
2
3
namespace Helmut\Forms\Fields\Search;
4
5
use Helmut\Forms\Field;
6
use Helmut\Forms\Utility\Validate;
7
8 View Code Duplication
class Search extends Field {
0 ignored issues
show
Duplication introduced by
This class 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...
9
10
    protected $value = '';
11 2
12
    public function getValue()
13 2
    {
14
        return $this->value;
15
    }
16 2
17
    public function getButtonName()
18 2
    {
19
        return $this->name.'_button';
20
    }   
21 2
22
    public function renderWith()
23 2
    {
24
        return ['value' => $this->value];
25
    }
26 2
27
    public function setValueFromDefault()
28 2
    {
29 2
        $this->value = $this->default;
30
    }
31
32
    public function setValueFromModel($model)
33
    {
34
        if (property_exists($model, $this->name)) $this->value = $model->{$this->name};
35
    }
36
37
    public function setValueFromRequest($request)
38
    {
39
        $this->value = $request->get($this->name);
40
    }
41
42
    public function fillModelWithValue($model)
43
    {
44
        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
45
    }   
46
    
47
    public function validateRequired()
48
    {
49
        return Validate::required($this->value);
50
    }
51
52
}