Completed
Push — master ( daab91...b549ed )
by Derek Stephen
02:54 queued 11s
created

CaptchaRender::renderBlock()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Del\Form\Renderer\Field;
4
5
use Del\Form\Field\Captcha;
6
use Del\Form\Field\FieldInterface;
7
use DOMDocument;
8
use DOMElement;
9
10
class CaptchaRender extends AbstractFieldRender implements FieldRendererInterface
11
{
12
    /**
13
     * @param FieldInterface $field
14
     * @param DOMElement $element
15
     * @return DOMElement
16
     */
17
    public function renderBlock(FieldInterface $field, DOMElement $element): DOMElement
18
    {
19
        if (!$field instanceof Captcha) {
20
            throw new InvalidArgumentException('Must be a Del\Form\Field\Captcha');
21
        }
22
23
        $dom = $this->getDom();
24
        $captcha = $dom->createDocumentFragment();
25
        $captcha->appendXML($field->getCaptchAdapter()->render());
26
27
        $div = $this->getDom()->createElement('div');
28
        $div->appendChild($captcha);
29
        $div->appendChild($element);
30
31
        return $div;
32
    }
33
}
34