Summary::getXML()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 0
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\Order;
13
14
use Riesenia\Pohoda\Common\OptionsResolver;
15
use Riesenia\Pohoda\Document\AbstractSummary;
16
17
class Summary extends AbstractSummary
18
{
19
    /** @var string[] */
20
    protected array $elements = [
21
        'roundingDocument',
22
        'roundingVAT',
23
        'homeCurrency',
24
        'foreignCurrency',
25
    ];
26
27
    /** @var string[] */
28
    protected array $additionalElements = [
29
        'typeCalculateVATInclusivePrice',
30
    ];
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 5
    public function getXML(): \SimpleXMLElement
36
    {
37 5
        if (is_null($this->namespace)) {
38 1
            throw new \LogicException('Namespace not set.');
39
        }
40
41 4
        if (is_null($this->nodePrefix)) {
42 1
            throw new \LogicException('Node name prefix not set.');
43
        }
44
45 3
        $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Summary', '', $this->namespace($this->namespace));
46
47 3
        $this->addElements($xml, \array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : [])), $this->namespace);
48
49 3
        return $xml;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 2
    protected function configureOptions(OptionsResolver $resolver): void
56
    {
57 2
        $resolver->setDefined(array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : [])));
58
59
        // validate / format options
60 2
        $resolver->setAllowedValues('roundingDocument', ['none', 'math2one', 'math2half', 'math2tenth', 'math5cent', 'up2one', 'up2half', 'up2tenth', 'down2one', 'down2half', 'down2tenth']);
61 2
        $resolver->setAllowedValues('roundingVAT', ['none', 'noneEveryRate', 'up2tenthEveryItem', 'up2tenthEveryRate', 'math2tenthEveryItem', 'math2tenthEveryRate', 'math2halfEveryItem', 'math2halfEveryRate', 'math2intEveryItem', 'math2intEveryRate']);
62
63 2
        if ($this->useOneDirectionalVariables) {
64 1
            $resolver->setNormalizer('typeCalculateVATInclusivePrice', $this->dependenciesFactory->getNormalizerFactory()->getClosure('string'));
65
        }
66
    }
67
}
68