Passed
Push — master ( 5c8579...6d694d )
by Petr
04:04
created

Summary   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 15
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 10 3
A getXML() 0 15 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 = ['roundingDocument', 'roundingVAT', 'homeCurrency', 'foreignCurrency'];
21
22
    /** @var string[] */
23
    protected array $additionalElements = ['typeCalculateVATInclusivePrice'];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 4
    public function getXML(): \SimpleXMLElement
29
    {
30 4
        if (is_null($this->namespace)) {
31 1
            throw new \LogicException('Namespace not set.');
32
        }
33
34 3
        if (is_null($this->nodePrefix)) {
35 1
            throw new \LogicException('Node name prefix not set.');
36
        }
37
38 2
        $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Summary', '', $this->namespace($this->namespace));
39
40 2
        $this->addElements($xml, \array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : [])), $this->namespace);
41
42 2
        return $xml;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    protected function configureOptions(OptionsResolver $resolver): void
49
    {
50 2
        $resolver->setDefined(array_merge($this->elements, ($this->useOneDirectionalVariables ? $this->additionalElements : [])));
51
52
        // validate / format options
53 2
        $resolver->setAllowedValues('roundingDocument', ['none', 'math2one', 'math2half', 'math2tenth', 'math5cent', 'up2one', 'up2half', 'up2tenth', 'down2one', 'down2half', 'down2tenth']);
54 2
        $resolver->setAllowedValues('roundingVAT', ['none', 'noneEveryRate', 'up2tenthEveryItem', 'up2tenthEveryRate', 'math2tenthEveryItem', 'math2tenthEveryRate', 'math2halfEveryItem', 'math2halfEveryRate', 'math2intEveryItem', 'math2intEveryRate']);
55
56 2
        if ($this->useOneDirectionalVariables) {
57 1
            $resolver->setNormalizer('typeCalculateVATInclusivePrice', $this->normalizerFactory->getClosure('string'));
58
        }
59
    }
60
}
61