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

Name::getProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
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