Completed
Branch dev-master (76dc67)
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 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 5
loc 16
ccs 10
cts 10
cp 1
rs 9.4285
c 0
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 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 1
    public function render(FieldInterface $field)
23
    {
24 1
        $helpBlock = $this->dom->createElement('span');
25 1
        $helpBlock->setAttribute('class', 'help-block');
26
27 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...
28 1
            $helpBlock = $this->addCustomErrorMessage($helpBlock, $field);
29
        } else {
30 1
            $helpBlock = $this->addErrorMessages($helpBlock, $field);
31
        }
32
33 1
        $div = $this->dom->createElement('div');
34 1
        $div->setAttribute('class', 'col-sm-offset-2 col-sm-10');
35 1
        $div->appendChild($helpBlock);
36 1
        return $div;
37
    }
38
39
    /**
40
     * @param DOMElement $helpBlock
41
     * @param FieldInterface $field
42
     * @return DOMElement
43
     */
44 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...
45
    {
46 1
        $message = $field->getCustomErrorMessage();
47 1
        $text = new DOMText($message);
48 1
        $helpBlock->appendChild($text);
49 1
        return $helpBlock;
50
    }
51
52
    /**
53
     * @param DOMElement $helpBlock
54
     * @param FieldInterface $field
55
     * @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...
56
     */
57 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...
58
    {
59 1
        $messages = $field->getMessages();
60
61 1
        foreach ($messages as $message) {
62 1
            $helpBlock = $this->appendMessage($helpBlock, $message);
63
        }
64 1
        return $helpBlock;
65
    }
66
67
    /**
68
     * @param DOMElement $helpBlock
69
     * @param $message
70
     * @return DOMElement
71
     */
72 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...
73
    {
74 1
        $text = new DOMText($message);
75 1
        $br = $this->dom->createElement('br');
76 1
        $helpBlock->appendChild($text);
77 1
        $helpBlock->appendChild($br);
78 1
        return $helpBlock;
79
    }
80
81
}