Completed
Push — issue/96 ( 542eb1...939878 )
by Alex
02:21
created

XmlAbstract::format()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 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\StandardAbstract;
16
use FeedIo\RuleSet;
17
use FeedIo\Rule\DateTimeBuilder;
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 11
    public function getItemNodeName()
74
    {
75 11
        return static::ITEM_NODE;
76
    }
77
78
    /**
79
     * @return XmlParser
80
     */
81
    public function newParser()
82
    {
83
        return new XmlParser($this, $this->logger);
0 ignored issues
show
Bug introduced by
The property logger does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
84
    }
85
86
    /**
87
     * Returns the RuleSet used to parse the feed's main node
88
     * @return \FeedIo\RuleSet
89
     */
90 12
    public function getFeedRuleSet()
91
    {
92 12
        if (is_null($this->feedRuleSet)) {
93 12
            $this->feedRuleSet = $this->buildFeedRuleSet();
94 12
        }
95
96 12
        return $this->feedRuleSet;
97
    }
98
99
    /**
100
     * @return \FeedIo\RuleSet
101
     */
102 10
    public function getItemRuleSet()
103
    {
104 10
        if (is_null($this->itemRuleSet)) {
105 10
            $this->itemRuleSet = $this->buildItemRuleSet();
106 10
        }
107
108 10
        return $this->itemRuleSet;
109
    }
110
111
    /**
112
     * @param  string        $tagName
113
     * @return ModifiedSince
114
     */
115 14
    public function getModifiedSinceRule($tagName)
116
    {
117 14
        $rule = new ModifiedSince($tagName);
118 14
        $rule->setDefaultFormat($this->getDefaultDateFormat());
119 14
        $rule->setDateTimeBuilder($this->dateTimeBuilder);
120
121 14
        return $rule;
122
    }
123
124
    /**
125
     * @return RuleSet
126
     */
127 14
    protected function buildBaseRuleSet()
128
    {
129 14
        $ruleSet = $ruleSet = new RuleSet();
130 14
        $ruleSet->add(new Title());
131
132 14
        return $ruleSet;
133
    }
134
}