Number::fillModelWithValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php 
2
3
namespace Helmut\Forms\Fields\Number;
4
5
use Helmut\Forms\Field;
6
use Helmut\Forms\Utility\Validate;
7
8 View Code Duplication
class Number 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
    protected $width = '30%';
12
13
    public function setWidth($width)
14
    {
15
        $this->width = $width;
16
        return $this;
17
    }
18 6
19
    public function getValue()
20 6
    {
21
        return $this->value;
22
    }
23 15
24
    public function getButtonName()
25 15
    {
26
        //
27
    }
28 4
29
    public function renderWith()
30 4
    {
31
        return [
32
            'value' => $this->value, 
33 15
            'width' => $this->width,
34
        ];
35 15
    }
36 15
37
    public function setValueFromDefault()
38 1
    {
39
        $this->value = $this->default;
40 1
    }
41 1
42
    public function setValueFromModel($model)
43
    {
44
        if (isset($model->{$this->name})) $this->value = $model->{$this->name};
45
    }
46
47
    public function setValueFromRequest($request)
48 1
    {
49
        $this->value = $request->get($this->name);
50 1
    }
51 1
52
    public function fillModelWithValue($model)
53 7
    {
54
        $model->{$this->name} = $this->value;
55 7
    }   
56
57
    public function validate()
58 7
    {
59
        $this->numeric();
0 ignored issues
show
Bug introduced by
The method numeric() does not exist on Helmut\Forms\Fields\Number\Number. Did you maybe mean validateNumeric()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
60 7
    }
61
62
    public function validateNumeric()
63 8
    {
64
        return Validate::numeric($this->value);
65 8
    }
66
67
    public function validateRequired()
68 1
    {
69
        return Validate::required($this->value);
70 1
    }
71 1
72
    public function validateBetween($min, $max)
73
    {
74 1
        return Validate::numericMin($this->value, $min) 
75
                && Validate::numericMax($this->value, $max);
76 1
    }
77
78
    public function validateMax($max)
79 1
    {
80
        return Validate::numericMax($this->value, $max);
81 1
    }
82
83
    public function validateMin($min)
84 1
    {
85
        return Validate::numericMin($this->value, $min);
86 1
    }
87
88
    public function validateInteger()
89 1
    {
90
        return Validate::integer($this->value);
91 1
    }
92
93
    public function validateIn($values = [])
94 1
    {
95
        return Validate::in($this->value, $values);
96 1
    }
97
98
    public function validateNotIn($values = [])
99
    {
100
        return Validate::notIn($this->value, $values);
101
    }
102
    
103
}