AbstractSummary   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 23
dl 0
loc 48
c 0
b 0
f 0
ccs 24
cts 24
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setData() 0 23 3
A getXML() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace kalanis\Pohoda\Document;
6
7
use kalanis\Pohoda\Common;
8
use kalanis\Pohoda\Type;
9
use kalanis\PohodaException;
10
11
/**
12
 * @property Common\Dtos\AbstractSummaryDto $data
13
 */
14
abstract class AbstractSummary extends AbstractPart
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 11
    public function setData(Common\Dtos\AbstractDto $data): parent
20
    {
21
        // process home currency
22 11
        if (isset($data->homeCurrency)) {
23 3
            $homeCurrency = new Type\CurrencyHome($this->dependenciesFactory);
24 3
            $homeCurrency
25 3
                ->setDirectionalVariable($this->useOneDirectionalVariables)
26 3
                ->setResolveOptions($this->resolveOptions)
27 3
                ->setData($data->homeCurrency);
28 3
            $data->homeCurrency = $homeCurrency;
29
        }
30
31
        // process foreign currency
32 11
        if (isset($data->foreignCurrency)) {
33 6
            $foreignCurrency = new Type\CurrencyForeign($this->dependenciesFactory);
34 6
            $foreignCurrency
35 6
                ->setDirectionalVariable($this->useOneDirectionalVariables)
36 6
                ->setResolveOptions($this->resolveOptions)
37 6
                ->setData($data->foreignCurrency);
38 6
            $data->foreignCurrency = $foreignCurrency;
39
        }
40
41 11
        return parent::setData($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::setData($data) returns the type kalanis\Pohoda\Document\AbstractPart which is incompatible with the type-hinted return parent.
Loading history...
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 10
    public function getXML(): \SimpleXMLElement
48
    {
49 10
        if (is_null($this->namespace)) {
50 1
            throw new PohodaException('Namespace not set.');
51
        }
52
53 9
        if (is_null($this->nodePrefix)) {
54 1
            throw new PohodaException('Node name prefix not set.');
55
        }
56
57 8
        $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Summary', '', $this->namespace($this->namespace));
58
59 8
        $this->addElements($xml, $this->getDataElements(), $this->namespace);
60
61 8
        return $xml;
62
    }
63
}
64