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

HorizontalFormErrorRender::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 5
Ratio 31.25 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 5
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 11
nc 2
nop 1
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 HorizontalFormErrorRender extends AbstractErrorRender implements ErrorRendererInterface
16
{
17
    /**
18
     * @param FieldInterface $field
19
     * @return DOMElement
20
     */
21 1
    public function render(FieldInterface $field)
22
    {
23 1
        $helpBlock = $this->dom->createElement('span');
24 1
        $helpBlock->setAttribute('class', 'help-block');
25
26 1 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
32 1
        $div = $this->dom->createElement('div');
33 1
        $div->setAttribute('class', 'col-sm-offset-2 col-sm-10');
34 1
        $div->appendChild($helpBlock);
35 1
        return $div;
36
    }
37
38
    /**
39
     * @param DOMElement $helpBlock
40
     * @param FieldInterface $field
41
     * @return DOMElement
42
     */
43 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...
44
    {
45 1
        $message = $field->getCustomErrorMessage();
46 1
        $text = new DOMText($message);
47 1
        $helpBlock->appendChild($text);
48 1
        return $helpBlock;
49
    }
50
51
    /**
52
     * @param DOMElement $helpBlock
53
     * @param FieldInterface $field
54
     * @return DOMElement]
0 ignored issues
show
Documentation introduced by
The doc-type DOMElement] could not be parsed: Expected "|" or "end of type", but got "]" at position 10. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
55
     */
56 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...
57
    {
58 1
        $messages = $field->getMessages();
59
60 1
        foreach ($messages as $message) {
61 1
            $helpBlock = $this->appendMessage($helpBlock, $message);
62 1
        }
63 1
        return $helpBlock;
64
    }
65
66
    /**
67
     * @param DOMElement $helpBlock
68
     * @param $message
69
     * @return DOMElement
70
     */
71 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...
72
    {
73 1
        $text = new DOMText($message);
74 1
        $br = $this->dom->createElement('br');
75 1
        $helpBlock->appendChild($text);
76 1
        $helpBlock->appendChild($br);
77 1
        return $helpBlock;
78
    }
79
80
}