PrinterSettings::setData()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.9332
cc 4
nc 8
nop 1
crap 4
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
use Riesenia\Pohoda\ValueTransformer\SanitizeEncoding;
17
18
class PrinterSettings extends AbstractAgenda
19
{
20
    /** @var string[] */
21
    protected array $elements = ['report', 'printer', 'pdf', 'parameters'];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 3
    public function setData(array $data): parent
27
    {
28
        // process report
29 3
        if (isset($data['report'])) {
30 3
            $report = new Report($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory);
31 3
            $data['report'] = $report->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['report']);
32
        }
33
        // process pdf
34 3
        if (isset($data['pdf'])) {
35 3
            $pdf = new Pdf($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory);
36 3
            $data['pdf'] = $pdf->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['pdf']);
37
        }
38
        // process parameters
39 3
        if (isset($data['parameters'])) {
40 3
            $parameters = new Parameters($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory);
41 3
            $data['parameters'] = $parameters->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['parameters']);
42
        }
43
44 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...
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 2
    public function getXML(): \SimpleXMLElement
51
    {
52 2
        $xml = $this->createXML()->addChild('prn:printerSettings', '', $this->namespace('prn'));
53
54 2
        $this->addElements($xml, $this->elements, 'prn');
55
56 2
        return $xml;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
63
    {
64
        // available options
65 1
        $resolver->setDefined($this->elements);
66
    }
67
}
68