AttributeHydration::assignAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Dgame\Soap\Hydrator;
4
5
use Dgame\Soap\Attribute\Attribute;
6
use Dgame\Soap\Element;
7
8
/**
9
 * Class AttributeHydration
10
 * @package Dgame\Soap\Hydrator
11
 */
12
final class AttributeHydration
13
{
14
    /**
15
     * @var Hydrate
16
     */
17
    private $hydrate;
18
19
    /**
20
     * AttributeHydration constructor.
21
     *
22
     * @param Hydrate $facade
23
     */
24
    public function __construct(Hydrate $facade)
25
    {
26
        $this->hydrate = $facade;
27
    }
28
29
    /**
30
     * @return Hydrate
31
     */
32
    public function getHydrate(): Hydrate
33
    {
34
        return $this->hydrate;
35
    }
36
37
    /**
38
     * @param Element $element
39
     */
40
    public function hydrate(Element $element)
41
    {
42
        $this->assignValue($element);
43
        $this->assignAttributes($element);
44
    }
45
46
    /**
47
     * @param Element $element
48
     */
49
    private function assignValue(Element $element)
50
    {
51
        if ($element->hasValue()) {
52
            $this->hydrate->assign('value', $element->getValue());
53
        }
54
    }
55
56
    /**
57
     * @param Element $element
58
     */
59
    private function assignAttributes(Element $element)
60
    {
61
        foreach ($element->getAttributes() as $attribute) {
62
            $this->assignAttribute($attribute);
63
        }
64
    }
65
66
    /**
67
     * @param Attribute $attribute
68
     */
69
    private function assignAttribute(Attribute $attribute)
70
    {
71
        if ($attribute->hasValue()) {
72
            $this->hydrate->assign($attribute->getName(), $attribute->getValue());
73
        }
74
    }
75
}