Parameter::getXML()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 22
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 9.2222
cc 6
nc 4
nop 0
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace kalanis\Pohoda\Type;
6
7
use kalanis\Pohoda\AbstractAgenda;
8
use kalanis\Pohoda\Common;
9
use kalanis\Pohoda\Type;
10
11
/**
12
 * @property Dtos\ParameterDto $data
13
 */
14
class Parameter extends AbstractAgenda
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 17
    public function getXML(): \SimpleXMLElement
20
    {
21 17
        $xml = $this->createXML()->addChild('typ:parameter', '', $this->namespace('typ'));
22
23 17
        $child = $this->data->name ?? null;
24 17
        $xml->addChild('typ:name', is_null($child) ? null : \strval($child));
25
26 17
        if (Type\Enums\ParameterTypeEnum::List->value == $this->data->type) {
27 13
            $this->addRefElement($xml, 'typ:listValueRef', $this->data->value);
28
29 13
            if (!empty($this->data->list)) {
30 13
                $this->addRefElement($xml, 'typ:list', $this->data->list);
31
            }
32
33 15
        } elseif (Type\Enums\ParameterTypeEnum::Boolean->value == $this->data->type) {
34 11
            $xml->addChild('typ:' . \strval($this->data->type) . 'Value', $this->data->value ? 'true' : 'false');
35
36
        } else {
37 15
            $xml->addChild('typ:' . \strval($this->data->type) . 'Value', \htmlspecialchars(\strval($this->data->value)));
38
        }
39
40 17
        return $xml;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 20
    protected function getDefaultDto(): Common\Dtos\AbstractDto
47
    {
48 20
        return new Dtos\ParameterDto();
49
    }
50
}
51