Passed
Push — master ( 221c35...fdb910 )
by Petr
02:59
created

AbstractHeader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getXML() 0 15 3
A setData() 0 23 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
10
/**
11
 * @property Common\Dtos\AbstractHeaderDto $data
12
 */
13
abstract class AbstractHeader extends AbstractPart
14
{
15
    use Common\AddParameterTrait;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 54
    public function setData(Common\Dtos\AbstractDto $data): parent
21
    {
22
        // process partner identity
23 54
        if (isset($data->partnerIdentity)) {
24 43
            $parentIdentity = new Type\Address($this->dependenciesFactory);
25 43
            $parentIdentity
26 43
                ->setDirectionalVariable($this->useOneDirectionalVariables)
27 43
                ->setResolveOptions($this->resolveOptions)
28 43
                ->setData($data->partnerIdentity);
29 43
            $data->partnerIdentity = $parentIdentity;
30
        }
31
32
        // process my identity
33 54
        if (isset($data->myIdentity)) {
34 27
            $myIdentity = new Type\MyAddress($this->dependenciesFactory);
35 27
            $myIdentity
36 27
                ->setDirectionalVariable($this->useOneDirectionalVariables)
37 27
                ->setResolveOptions($this->resolveOptions)
38 27
                ->setData($data->myIdentity);
39 27
            $data->myIdentity = $myIdentity;
40
        }
41
42 54
        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...
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 38
    public function getXML(): \SimpleXMLElement
49
    {
50 38
        if (is_null($this->namespace)) {
51 1
            throw new \LogicException('Namespace not set.');
52
        }
53
54 37
        if (is_null($this->nodePrefix)) {
55 1
            throw new \LogicException('Node name prefix not set.');
56
        }
57
58 36
        $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Header', '', $this->namespace($this->namespace));
59
60 36
        $this->addElements($xml, $this->getDataElements(), $this->namespace);
61
62 36
        return $xml;
63
    }
64
}
65