PrintRequest::getXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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
 *     record: PrintRequest\Record,
17
 *     printerSettings: PrintRequest\PrinterSettings,
18
 * } $data
19
 */
20
class PrintRequest extends AbstractAgenda
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    public function setData(array $data): parent
26
    {
27
        // process record
28 3
        $record = new PrintRequest\Record($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory);
29 3
        $record->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($data['record']);
30 3
        $data['record'] = $record;
31
32
        // process printer settings
33 3
        $printerSettings = new PrintRequest\PrinterSettings($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory);
34 3
        $printerSettings->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($data['printerSettings']);
35 3
        $data['printerSettings'] = $printerSettings;
36
37 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...
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 2
    public function getXML(): \SimpleXMLElement
44
    {
45 2
        $xml = $this->createXML()->addChild('prn:print', '', $this->namespace('prn'));
46 2
        $xml->addAttribute('version', '1.0');
47
48 2
        $this->addElements($xml, ['record', 'printerSettings'], '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(['record', 'printerSettings']);
60
61 1
        $resolver->setRequired('record');
62 1
        $resolver->setRequired('printerSettings');
63
    }
64
}
65