Completed
Push — master ( 7150c8...077dd8 )
by Derek Stephen
9s
created

DefaultErrorRender::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
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\Field\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 DOMElement $div
0 ignored issues
show
Bug introduced by
There is no parameter named $div. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
19
     * @param FieldInterface $field
20
     * @return DOMElement
21
     */
22 2
    public function render(FieldInterface $field)
23
    {
24 2
        $helpBlock = $this->dom->createElement('span');
25 2
        $helpBlock->setAttribute('class', 'help-block');
26
27 2
        if ($field->hasCustomErrorMessage()) {
28 1
            $helpBlock = $this->addCustomErrorMessage($helpBlock, $field);
29
        } else {
30 1
            $helpBlock = $this->addErrorMessages($helpBlock, $field);
31
        }
32 2
        return $helpBlock;
33
    }
34
35
    /**
36
     * @param DOMElement $helpBlock
37
     * @param FieldInterface $field
38
     * @return DOMElement
39
     */
40 1
    private function addCustomErrorMessage(DOMElement $helpBlock, FieldInterface $field)
41
    {
42 1
        $message = $field->getCustomErrorMessage();
43 1
        $text = new DOMText($message);
44 1
        $helpBlock->appendChild($text);
45 1
        return $helpBlock;
46
    }
47
48
    /**
49
     * @param DOMElement $helpBlock
50
     * @param FieldInterface $field
51
     * @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...
52
     */
53 1
    private function addErrorMessages(DOMElement $helpBlock, FieldInterface $field)
54
    {
55 1
        $messages = $field->getMessages();
56
57 1
        foreach ($messages as $message) {
58 1
            $helpBlock = $this->appendMessage($helpBlock, $message);
59
        }
60 1
        return $helpBlock;
61
    }
62
63
    /**
64
     * @param DOMElement $helpBlock
65
     * @param $message
66
     * @return DOMElement
67
     */
68 1
    private function appendMessage(DOMElement $helpBlock, $message)
69
    {
70 1
        $text = new DOMText($message);
71 1
        $br = $this->dom->createElement('br');
72 1
        $helpBlock->appendChild($text);
73 1
        $helpBlock->appendChild($br);
74 1
        return $helpBlock;
75
    }
76
77
}