Parameters   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
c 2
b 0
f 0
dl 0
loc 46
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 7 1
A getXML() 0 7 1
A setData() 0 14 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 = ['copy', 'datePrint'];
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    public function setData(array $data): parent
26
    {
27 3
        $factory = new ParameterFactory($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->normalizerFactory);
28
29 3
        foreach ($factory->getKeys() as $key) {
30
            // fill elements from factory
31 3
            $this->elements[] = $key;
32
            // add instance to data
33 3
            if (isset($data[$key])) {
34 3
                $data[$key] = $factory->getByKey($key, $this->resolveOptions)->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data[$key]);
35
            }
36
        }
37
38 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...
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function getXML(): \SimpleXMLElement
45
    {
46 2
        $xml = $this->createXML()->addChild('prn:parameters', '', $this->namespace('prn'));
47
48 2
        $this->addElements($xml, $this->elements, 'prn');
49
50 2
        return $xml;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
57
    {
58
        // available options
59 1
        $resolver->setDefined($this->elements);
60
61 1
        $resolver->setNormalizer('copy', $this->normalizerFactory->getClosure('int'));
62 1
        $resolver->setNormalizer('datePrint', $this->normalizerFactory->getClosure('string'));
63
    }
64
}
65