AbstractHeader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 25
c 0
b 0
f 0
dl 0
loc 59
ccs 26
cts 26
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getXML() 0 15 3
A configureOptions() 0 4 1
A setData() 0 23 3
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\Document;
13
14
use Riesenia\Pohoda\Common;
15
use Riesenia\Pohoda\Type;
16
17
/**
18
 * @property array{
19
 *     parameters?: iterable<Type\Parameter>,
20
 *     partnerIdentity?: Type\Address,
21
 *     myIdentity?: Type\MyAddress,
22
 * } $data
23
 */
24
abstract class AbstractHeader extends AbstractPart
25
{
26
    use Common\AddParameterTrait;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 54
    public function setData(array $data): parent
32
    {
33
        // process partner identity
34 54
        if (isset($data['partnerIdentity'])) {
35 43
            $parentIdentity = new Type\Address($this->dependenciesFactory);
36 43
            $parentIdentity
37 43
                ->setDirectionalVariable($this->useOneDirectionalVariables)
38 43
                ->setResolveOptions($this->resolveOptions)
39 43
                ->setData($data['partnerIdentity']);
40 43
            $data['partnerIdentity'] = $parentIdentity;
41
        }
42
43
        // process my identity
44 54
        if (isset($data['myIdentity'])) {
45 27
            $myIdentity = new Type\MyAddress($this->dependenciesFactory);
46 27
            $myIdentity
47 27
                ->setDirectionalVariable($this->useOneDirectionalVariables)
48 27
                ->setResolveOptions($this->resolveOptions)
49 27
                ->setData($data['myIdentity']);
50 27
            $data['myIdentity'] = $myIdentity;
51
        }
52
53 54
        return parent::setData($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::setData($data) returns the type Riesenia\Pohoda\Document\AbstractPart which is incompatible with the type-hinted return parent.
Loading history...
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 38
    public function getXML(): \SimpleXMLElement
60
    {
61 38
        if (is_null($this->namespace)) {
62 1
            throw new \LogicException('Namespace not set.');
63
        }
64
65 37
        if (is_null($this->nodePrefix)) {
66 1
            throw new \LogicException('Node name prefix not set.');
67
        }
68
69 36
        $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Header', '', $this->namespace($this->namespace));
70
71 36
        $this->addElements($xml, \array_merge($this->elements, ['parameters']), $this->namespace);
72
73 36
        return $xml;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 8
    protected function configureOptions(Common\OptionsResolver $resolver): void
80
    {
81
        // available options
82 8
        $resolver->setDefined($this->elements);
83
    }
84
}
85