IntParam::setData()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.9332
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
/**
4
 * This file is part of riesenia/pohoda package.
5
 *
6
 * Licensed under the MIT License
7
 * (c) RIESENIA.com
8
 */
9
10
declare(strict_types=1);
11
12
namespace Riesenia\Pohoda;
13
14
/**
15
 * @property array{
16
 *     name: string,
17
 *     description?: string,
18
 *     parameterType: string,
19
 *     parameterSettings?: IntParam\Settings,
20
 * } $data
21
 */
22
class IntParam extends AbstractAgenda
23
{
24
    /** @var string[] */
25
    protected array $elements = [
26
        'name',
27
        'description',
28
        'parameterType',
29
        'parameterSettings',
30
    ];
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 3
    public function setData(array $data): parent
36
    {
37
        // prepare empty parameter list for list
38 3
        if ('listValue' == $data['parameterType']) {
39 1
            $data['parameterSettings'] = ['parameterList' => []];
40
        }
41
42
        // process settings
43 3
        if (isset($data['parameterSettings'])) {
44 3
            $parameterSettings = new IntParam\Settings($this->dependenciesFactory);
45 3
            $parameterSettings
46 3
                ->setDirectionalVariable($this->useOneDirectionalVariables)
47 3
                ->setResolveOptions($this->resolveOptions)
48 3
                ->setData($data['parameterSettings']);
49 3
            $data['parameterSettings'] = $parameterSettings;
50
        }
51
52 3
        return parent::setData($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::setData($data) returns the type Riesenia\Pohoda\AbstractAgenda which is incompatible with the type-hinted return parent.
Loading history...
53
    }
54
55 1
    public function getImportRoot(): string
56
    {
57 1
        return 'lst:intParamDetail';
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 2
    public function getXML(): \SimpleXMLElement
64
    {
65 2
        $xml = $this->createXML()->addChild('ipm:intParamDetail', '', $this->namespace('ipm'));
66 2
        $xml->addAttribute('version', '2.0');
67
68 2
        $param = $xml->addChild('ipm:intParam');
69 2
        $this->addElements($param, $this->elements, 'ipm');
70
71 2
        return $xml;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
78
    {
79
        // available options
80 1
        $resolver->setDefined($this->elements);
81
82
        // validate / format options
83 1
        $resolver->setRequired('name');
84 1
        $resolver->setRequired('parameterType');
85 1
        $resolver->setAllowedValues('parameterType', ['textValue', 'currencyValue', 'booleanValue', 'numberValue', 'integerValue', 'datetimeValue', 'unit', 'listValue']);
86
    }
87
}
88