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

Email   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 55
loc 55
c 0
b 0
f 0
wmc 12
lcom 1
cbo 3
rs 10
ccs 21
cts 21
cp 1

10 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 validate() 4 4 1
A validateEmail() 4 4 1
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\Email;
4
5
use Helmut\Forms\Field;
6
use Helmut\Forms\Utility\Validate;
7
8 View Code Duplication
class Email 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 8
12
    public function getValue()
13 8
    {
14
        return $this->value;
15
    }
16 12
17
    public function getButtonName()
18 12
    {
19
        //
20
    }
21 4
22
    public function renderWith()
23 4
    {
24
        return ['value' => $this->value];
25
    }
26 11
27
    public function setValueFromDefault()
28 11
    {
29 11
        $this->value = $this->default;
30
    }
31 1
32
    public function setValueFromModel($model)
33 1
    {
34 1
        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 1
42
    public function fillModelWithValue($model)
43 1
    {
44 1
        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
45
    }
46 2
47
    public function validate()
48 2
    {
49
        return $this->email();
0 ignored issues
show
Documentation Bug introduced by
The method email does not exist on object<Helmut\Forms\Fields\Email\Email>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
50
    }
51 2
52
    public function validateEmail()
53 2
    {
54
        return Validate::email($this->value);
55
    }
56 3
57
    public function validateRequired()
58 3
    {
59
        return Validate::required($this->value);
60
    }
61
62
}
63