Completed
Push — issue/134 ( 534dd9 )
by Alex
02:01
created

Rdf::canHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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 DOMDocument;
14
use FeedIo\Reader\Document;
15
use FeedIo\RuleSet;
16
use FeedIo\Rule\Structure;
17
18
class Rdf extends Rss
19
{
20
21
    /**
22
     * Format version
23
     */
24
    const VERSION = '1.0';
25
26
    /**
27
     * RDF document must have a <rdf> root node
28
     */
29
    const ROOT_NODE_TAGNAME = 'rdf';
30
31
    /**
32
     * publication date
33
     */
34
    const DATE_NODE_TAGNAME = 'dc:date';
35
36
    /**
37
     * Tells if the parser can handle the feed or not
38
     * @param  Document $document
39
     * @return boolean
40
     */
41
    public function canHandle(Document $document)
42
    {
43
        return false !== strpos($document->getDOMDocument()->documentElement->tagName, static::ROOT_NODE_TAGNAME);
44
    }
45
46
    /**
47
     * @param  DOMDocument $document
48
     * @return \DomElement
49
     */
50
    public function getMainElement(\DOMDocument $document)
51
    {
52
        return $document->documentElement;
53
    }
54
55
    /**
56
     * @return RuleSet
57
     */
58
    public function buildFeedRuleSet()
59
    {
60
        $ruleSet = new RuleSet();
61
        $ruleSet->add(new Structure(static::CHANNEL_NODE_TAGNAME, $this->buildItemRuleSet()));
62
63
        return $ruleSet;
64
    }
65
}
66