Completed
Push — master ( be72f0...b6ccc1 )
by Alex
17s queued 14s
created

FeedProcessor::handleChildComplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace POData\Readers\Atom\Processors;
7
8
use POData\Common\ODataConstants;
9
use POData\ObjectModel\ODataFeed;
10
use POData\ObjectModel\ODataLink;
11
use POData\ObjectModel\ODataTitle;
12
13
class FeedProcessor extends BaseNodeHandler
14
{
15
16
17
    /**
18
     * @var ODataFeed
19
     */
20
    private $oDataFeed;
21
22
    private $titleType;
23
24
    public function __construct()
25
    {
26
        $this->oDataFeed = new ODataFeed();
27
    }
28
29
    public function handleStartNode($tagNamespace, $tagName, $attributes)
30
    {
31
        assert(
32
            strtolower(ODataConstants::ATOM_NAMESPACE) === strtolower($tagNamespace) ||
33
            strtolower(ODataConstants::ODATA_METADATA_NAMESPACE) === strtolower($tagNamespace)
34
        );
35
        parent::handleStartNode($tagNamespace, $tagName, $attributes);
36
    }
37
    public function handleStartAtomId()
38
    {
39
        $this->enqueueEnd(function () {
40
            $this->oDataFeed->id = $this->popCharData();
41
        });
42
    }
43
    public function handleStartAtomTitle($attributes)
44
    {
45
        $this->titleType = $this->arrayKeyOrDefault(
46
            $attributes,
47
            ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME,
48
            ''
49
        );
50
        $this->enqueueEnd(function () {
51
            $this->oDataFeed->title = new ODataTitle($this->popCharData(), $this->titleType);
52
            $this->titleType        = null;
53
        });
54
    }
55
    public function handleStartAtomUpdated()
56
    {
57
        $this->enqueueEnd(function () {
58
            $this->oDataFeed->updated = $this->popCharData();
59
        });
60
    }
61
62
    public function handleStartAtomLink($attributes)
63
    {
64
        $rel                      = $this->arrayKeyOrDefault($attributes, ODataConstants::ATOM_LINK_RELATION_ATTRIBUTE_NAME, '');
65
        $prop                     = $rel === ODataConstants::ATOM_SELF_RELATION_ATTRIBUTE_VALUE ? 'selfLink' : 'nextPageLink';
66
        $this->oDataFeed->{$prop} = new ODataLink(
67
            $this->arrayKeyOrDefault($attributes, ODataConstants::ATOM_LINK_RELATION_ATTRIBUTE_NAME, ''),
68
            $this->arrayKeyOrDefault($attributes, ODataConstants::ATOM_TITLE_ELELMET_NAME, ''),
69
            $this->arrayKeyOrDefault($attributes, ODataConstants::ATOM_TYPE_ATTRIBUTE_NAME, ''),
70
            $this->arrayKeyOrDefault($attributes, ODataConstants::ATOM_HREF_ATTRIBUTE_NAME, '')
71
        );
72
        $this->enqueueEnd($this->doNothing());
73
    }
74
75
    public function handleStartMetadataCount()
76
    {
77
        $this->enqueueEnd(function () {
78
            $this->oDataFeed->rowCount =  (int)$this->popCharData();
79
        });
80
    }
81
82
    public function handleChildComplete($objectModel)
83
    {
84
        //assert($objectModel instanceof ODataEntry);
85
        $this->oDataFeed->entries[] = $objectModel;
86
    }
87
88
    public function getObjetModelObject()
89
    {
90
        return $this->oDataFeed;
91
    }
92
}
93