Completed
Push — release/3.0 ( 106435...2e0212 )
by Alex
01:55
created

XmlAbstract::getItemNodeName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Standard;
12
13
use FeedIo\Formatter\XmlFormatter;
14
use FeedIo\StandardAbstract;
15
use FeedIo\RuleSet;
16
use FeedIo\Rule\ModifiedSince;
17
use FeedIo\Rule\Title;
18
19
abstract class XmlAbstract extends StandardAbstract
20
{
21
22
    /**
23
     * Name of the node containing all the feed's items
24
     */
25
    const ITEM_NODE = 'item';
26
27
    /**
28
     * This is for XML Standards
29
     */
30
    const SYNTAX_FORMAT = 'Xml';
31
32
    /**
33
     * RuleSet used to parse the feed's main node
34
     * @var \FeedIo\RuleSet
35
     */
36
    protected $feedRuleSet;
37
38
    /**
39
     * @var \FeedIo\RuleSet
40
     */
41
    protected $itemRuleSet;
42
43
    /**
44
     * Formats the document according to the standard's specification
45
     * @param  \DOMDocument $document
46
     * @return mixed
47
     */
48
    abstract public function format(\DOMDocument $document);
49
50
    /**
51
     * @param  \DOMDocument $document
52
     * @return \DomElement
53
     */
54
    abstract public function getMainElement(\DOMDocument $document);
55
56
    /**
57
     * Builds and returns a rule set to parse the root node
58
     * @return \FeedIo\RuleSet
59
     */
60
    abstract public function buildFeedRuleSet();
61
62
    /**
63
     * Builds and returns a rule set to parse an item
64
     * @return \FeedIo\RuleSet
65
     */
66
    abstract public function buildItemRuleSet();
67
68
    /**
69
     * @return string
70
     */
71 13
    public function getItemNodeName()
72
    {
73 13
        return static::ITEM_NODE;
74 1
    }
75
76
    /**
77
     * @return XmlFormatter
78
     */
79
    public function getFormatter()
80
    {
81
        return new XmlFormatter($this);
82
    }
83
84
    /**
85
     * Returns the RuleSet used to parse the feed's main node
86
     * @return \FeedIo\RuleSet
87
     */
88 14
    public function getFeedRuleSet()
89
    {
90 14
        if (is_null($this->feedRuleSet)) {
91 14
            $this->feedRuleSet = $this->buildFeedRuleSet();
92 14
        }
93
94 14
        return $this->feedRuleSet;
95
    }
96
97
    /**
98
     * @return \FeedIo\RuleSet
99
     */
100 12
    public function getItemRuleSet()
101
    {
102 12
        if (is_null($this->itemRuleSet)) {
103 12
            $this->itemRuleSet = $this->buildItemRuleSet();
104 12
        }
105
106 12
        return $this->itemRuleSet;
107
    }
108
109
    /**
110
     * @param  string        $tagName
111
     * @return ModifiedSince
112
     */
113 16
    public function getModifiedSinceRule($tagName)
114
    {
115 16
        $rule = new ModifiedSince($tagName);
116 16
        $rule->setDefaultFormat($this->getDefaultDateFormat());
117 16
        $rule->setDateTimeBuilder($this->dateTimeBuilder);
118
119 16
        return $rule;
120
    }
121
122
    /**
123
     * @return RuleSet
124
     */
125 16
    protected function buildBaseRuleSet()
126
    {
127 16
        $ruleSet = $ruleSet = new RuleSet();
128 16
        $ruleSet->add(new Title());
129
130 16
        return $ruleSet;
131
    }
132
}
133