Parameters::setData()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 9.9
cc 3
nc 3
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\PrintRequest;
13
14
use Riesenia\Pohoda\AbstractAgenda;
15
use Riesenia\Pohoda\Common;
16
17
class Parameters extends AbstractAgenda
18
{
19
    /** @var string[] */
20
    protected array $elements = [
21
        'copy',
22
        'datePrint',
23
    ];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 3
    public function setData(array $data): parent
29
    {
30 3
        $parameterFactory = $this->dependenciesFactory->getParametersFactory();
31 3
        $parameterInstances = $this->dependenciesFactory->getParameterInstances();
32
33 3
        foreach ($parameterInstances->getKeys() as $key) {
34
            // fill elements from factory
35 3
            $this->elements[] = $key;
36
            // add instance to data
37 3
            if (isset($data[$key])) {
38 3
                $data[$key] = $parameterFactory
39 3
                    ->getByClassName($parameterInstances->getByKey($key))
40 3
                    ->setDirectionalVariable($this->useOneDirectionalVariables)
41 3
                    ->setResolveOptions($this->resolveOptions)
42 3
                    ->setData($data[$key]);
43
            }
44
        }
45
46 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...
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 2
    public function getXML(): \SimpleXMLElement
53
    {
54 2
        $xml = $this->createXML()->addChild('prn:parameters', '', $this->namespace('prn'));
55
56 2
        $this->addElements($xml, $this->elements, 'prn');
57
58 2
        return $xml;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
65
    {
66
        // available options
67 1
        $resolver->setDefined($this->elements);
68
69 1
        $resolver->setNormalizer('copy', $this->dependenciesFactory->getNormalizerFactory()->getClosure('int'));
70 1
        $resolver->setNormalizer('datePrint', $this->dependenciesFactory->getNormalizerFactory()->getClosure('string'));
71
    }
72
}
73