Completed
Push — master ( 077dd8...ca59d5 )
by Derek Stephen
01:55
created

DefaultErrorRender   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 46.77 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 29
loc 62
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addCustomErrorMessage() 7 7 1
A appendMessage() 8 8 1
A render() 5 12 2
A addErrorMessages() 9 9 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
 * User: delboy1978uk
4
 * Date: 04/12/2016
5
 * Time: 23:36
6
 */
7
8
namespace Del\Form\Renderer\Error;
9
10
11
use Del\Form\Field\FieldInterface;
12
use DOMElement;
13
use DOMText;
14
15
class DefaultErrorRender extends AbstractErrorRender implements ErrorRendererInterface
16
{
17
    /**
18
     * @param FieldInterface $field
19
     * @return DOMElement
20
     */
21 2
    public function render(FieldInterface $field)
22
    {
23 2
        $helpBlock = $this->dom->createElement('span');
24 2
        $helpBlock->setAttribute('class', 'help-block');
25
26 2 View Code Duplication
        if ($field->hasCustomErrorMessage()) {
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...
27 1
            $helpBlock = $this->addCustomErrorMessage($helpBlock, $field);
28 1
        } else {
29 1
            $helpBlock = $this->addErrorMessages($helpBlock, $field);
30
        }
31 2
        return $helpBlock;
32
    }
33
34
    /**
35
     * @param DOMElement $helpBlock
36
     * @param FieldInterface $field
37
     * @return DOMElement
38
     */
39 1 View Code Duplication
    private function addCustomErrorMessage(DOMElement $helpBlock, FieldInterface $field)
0 ignored issues
show
Duplication introduced by
This method 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...
40
    {
41 1
        $message = $field->getCustomErrorMessage();
42 1
        $text = new DOMText($message);
43 1
        $helpBlock->appendChild($text);
44 1
        return $helpBlock;
45
    }
46
47
    /**
48
     * @param DOMElement $helpBlock
49
     * @param FieldInterface $field
50
     * @return DOMElement
51
     */
52 1 View Code Duplication
    private function addErrorMessages(DOMElement $helpBlock, FieldInterface $field)
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54 1
        $messages = $field->getMessages();
55
56 1
        foreach ($messages as $message) {
57 1
            $helpBlock = $this->appendMessage($helpBlock, $message);
58 1
        }
59 1
        return $helpBlock;
60
    }
61
62
    /**
63
     * @param DOMElement $helpBlock
64
     * @param $message
65
     * @return DOMElement
66
     */
67 1 View Code Duplication
    private function appendMessage(DOMElement $helpBlock, $message)
0 ignored issues
show
Duplication introduced by
This method 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...
68
    {
69 1
        $text = new DOMText($message);
70 1
        $br = $this->dom->createElement('br');
71 1
        $helpBlock->appendChild($text);
72 1
        $helpBlock->appendChild($br);
73 1
        return $helpBlock;
74
    }
75
76
}