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

XmlAbstract   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 8
lcom 3
cbo 5
dl 0
loc 114
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
format() 0 1 ?
getMainElement() 0 1 ?
buildFeedRuleSet() 0 1 ?
buildItemRuleSet() 0 1 ?
A getItemNodeName() 0 4 1
A getFormatter() 0 4 1
A getItemRuleSet() 0 8 2
A getModifiedSinceRule() 0 8 1
A buildBaseRuleSet() 0 7 1
A getFeedRuleSet() 0 8 2
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