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

DefaultErrorRender::addErrorMessages()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
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
}