Completed
Branch dev-master (f3e1e5)
by Derek Stephen
20:25
created

SelectRender::processOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
crap 2
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 4
    public function renderBlock(FieldInterface $field, DOMElement $element)
23
    {
24 4
        if (!$field instanceof Select) {
25 1
            throw new InvalidArgumentException('Must be a Del\Form\Field\Select');
26
        }
27 3
        foreach ($field->getOptions() as $value => $label) {
28 3
            $option = $this->processOption($field, $value, $label);
29 3
            $element->appendChild($option);
30
        }
31 3
        return $element;
32
    }
33
34
    /**
35
     * @param FieldInterface $field
36
     * @param DOMElement $option
0 ignored issues
show
Bug introduced by
There is no parameter named $option. 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...
37
     * @return DOMElement
38
     */
39 3
    private function processOption(FieldInterface $field, $value, $label)
40
    {
41 3
        $option = $this->dom->createElement('option');
42 3
        $option->setAttribute('value', $value);
43 3
        $option->textContent = $label;
44 3
        if($field->getValue() == $option->getAttribute('value')) {
45 1
            $option->setAttribute('selected', 'selected');
46
        }
47 3
        return $option;
48
    }
49
}