Completed
Branch dev-master (76dc67)
by Derek Stephen
01:55
created

HorizontalFormErrorRender   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 43.28 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 5 16 2
A addCustomErrorMessage() 7 7 1
A addErrorMessages() 9 9 2
A appendMessage() 8 8 1

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 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
}