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

SelectRender::renderFieldBlock()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0582

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
ccs 11
cts 13
cp 0.8462
rs 9.2
c 1
b 0
f 0
cc 4
eloc 13
nc 5
nop 5
crap 4.0582
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 $element
20
     * @return DOMElement
21
     */
22 3
    public function renderBlock(FieldInterface $field, DOMElement $element)
23
    {
24 3
        if (!$field instanceof Select) {
25 1
            throw new InvalidArgumentException('Must be a Del\Form\Field\Select');
26
        }
27 2
        foreach ($field->getOptions() as $value => $label) {
28 2
            $option = $this->dom->createElement('option');
29 2
            $option->setAttribute('value', $value);
30 2
            $option->textContent = $label;
31 2
            $element->appendChild($option);
32 2
        }
33 2
        return $element;
34
    }
35
}