Completed
Pull Request — master (#1)
by Derek Stephen
02:21
created

SelectRender   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 28
ccs 11
cts 13
cp 0.8462
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderFieldBlock() 0 18 4
1
<?php
2
/**
3
 * User: delboy1978uk
4
 * Date: 04/12/2016
5
 * Time: 22:33
6
 */
7
8
namespace Del\Form\Renderer\Field;
9
10
use Del\Form\Field\FieldInterface;
11
use Del\Form\Field\Select;
12
use DOMElement;
13
use InvalidArgumentException;
14
15
class SelectRender extends AbstractFieldRender implements FieldRendererInterface
16
{
17
    /**
18
     * @param FieldInterface $field
19
     * @param DOMElement $fieldBlock
20
     * @param DOMElement $labelBlock
21
     * @param DOMElement $element
22
     * @param DOMElement|null $errorBlock
23
     */
24 1
    public function renderFieldBlock(FieldInterface $field, DOMElement $fieldBlock, DOMElement $labelBlock, DOMElement $element, DOMElement $errorBlock = null)
25
    {
26 1
        if (!$field instanceof Select) {
27
            throw new InvalidArgumentException('Must be a Del\Form\Field\Select');
28
        }
29 1
        foreach ($field->getOptions() as $value => $label) {
30 1
            $option = $this->dom->createElement('option');
31 1
            $option->setAttribute('value', $value);
32 1
            $option->textContent = $label;
33 1
            $element->appendChild($option);
34
        }
35 1
        $fieldBlock->appendChild($labelBlock);
36 1
        $fieldBlock->appendChild($element);
37 1
        if ($errorBlock) {
38
            $fieldBlock->appendChild($errorBlock);
39
        }
40 1
        return $fieldBlock;
41
    }
42
}