Completed
Push — master ( 471a2c...9baf90 )
by Alex
14s
created

XmlAbstract::getFormatter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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