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

FormRenderer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 17.95 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 7
loc 39
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderFieldLabel() 7 7 1
A renderFieldBlock() 0 21 4

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: 29/11/2016
5
 * Time: 19:44
6
 */
7
8
namespace Del\Form\Renderer;
9
10
use Del\Form\Field\CheckBox;
11
use Del\Form\Field\Radio;
12
use DOMElement;
13
use DOMText;
14
15
class FormRenderer extends AbstractFormRenderer implements FormRendererInterface
16
{
17
    /**
18
     * @return DOMElement
19
     */
20 7 View Code Duplication
    public function renderFieldLabel()
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...
21
    {
22 7
        $label = $this->createLabelElement();
23 7
        $text = new DOMText($this->field->getLabel());
24 7
        $label->appendChild($text);
25 7
        return $label;
26
    }
27
28
    /**
29
     * @return DOMElement
30
     */
31 6
    public function renderFieldBlock()
32
    {
33
        // Set form group div properties
34 6
        $formGroup = $this->block;
35 6
        $class = $formGroup->getAttribute('class').'form-group';
36 6
        $formGroup->setAttribute('class', $class);
37
38
        // add the label div, form field, and error div, if any.
39 6
        if (!$this->field instanceof Radio && !$this->field instanceof CheckBox) {
40 6
            $formGroup->appendChild($this->label);
41 6
        }
42
43 6
        $formGroup->appendChild($this->element);
44
45 6
        if (!is_null($this->errors)) {
46 2
            $formGroup->appendChild($this->errors);
47 2
        }
48
49
        // Field rendered! Pass it back!
50 6
        return $formGroup;
51
    }
52
53
}