Completed
Push — master ( e960f4...d2d510 )
by Randy
02:01
created

Hydrator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClassMapper() 0 4 1
A hydrate() 0 12 3
A assemble() 0 4 1
A dehydrate() 0 7 1
1
<?php
2
3
namespace Dgame\Soap\Hydrator;
4
5
use Dgame\Soap\Element;
6
use DOMDocument;
7
use DOMNode;
8
9
/**
10
 * Class Hydrator
11
 * @package Dgame\Soap\Hydrator
12
 */
13
final class Hydrator
14
{
15
    /**
16
     * @var ClassMapper
17
     */
18
    private $mapper;
19
20
    /**
21
     * Hydrator constructor.
22
     *
23
     * @param ClassMapper $mapper
24
     */
25
    public function __construct(ClassMapper $mapper)
26
    {
27
        $this->mapper = $mapper;
28
    }
29
30
    /**
31
     * @return ClassMapper
32
     */
33
    public function getClassMapper(): ClassMapper
34
    {
35
        return $this->mapper;
36
    }
37
38
    /**
39
     * @param DOMNode $node
40
     *
41
     * @return object|null
42
     */
43
    public function hydrate(DOMNode $node)
44
    {
45
        $element = Translator::new()->translate($node);
46
        if ($element !== null) {
47
            $hydration = new ElementHydration($this->mapper);
48
            $element->accept($hydration);
49
50
            return $hydration->isHydrated() ? $hydration->getHydrate()->getFacade()->getObject() : null;
51
        }
52
53
        return null;
54
    }
55
56
    /**
57
     * @param AssemblableInterface $assemblable
58
     *
59
     * @return DOMDocument
60
     */
61
    public function assemble(AssemblableInterface $assemblable): DOMDocument
62
    {
63
        return $this->dehydrate($assemblable->assemble());
64
    }
65
66
    /**
67
     * @param Element $element
68
     *
69
     * @return DOMDocument
70
     */
71
    public function dehydrate(Element $element): DOMDocument
72
    {
73
        $assembler = new Assembler();
74
        $element->accept($assembler);
75
76
        return $assembler->getDocument();
77
    }
78
}