Completed
Push — issue/96 ( 8680e7...cc85b0 )
by Alex
02:21
created

XmlAbstract::buildBaseRuleSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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