Completed
Push — master ( 4c7da2...64af60 )
by Alex
02:34 queued 46s
created

ModifiedSince::addElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 3
crap 2
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\Rule;
12
13
use FeedIo\Feed\NodeInterface;
14
use FeedIo\DateRuleAbstract;
15
16
class ModifiedSince extends DateRuleAbstract
17
{
18
    const NODE_NAME = 'pubDate';
19
20
    /**
21
     * @param  NodeInterface $node
22
     * @param  \DOMElement   $element
23
     */
24 8
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
25
    {
26 8
        $node->setLastModified($this->getDateTimeBuilder()->convertToDateTime($element->nodeValue));
27 8
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32 4
    protected function hasValue(NodeInterface $node) : bool
33
    {
34 4
        return true;
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40 4
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
41
    {
42 4
        $date = is_null($node->getLastModified()) ? new \DateTime():$node->getLastModified();
43
44 4
        $rootElement->appendChild($document->createElement(
45 4
            $this->getNodeName(),
46 4
            $date->format($this->getDefaultFormat())
47
        ));
48 4
    }
49
}
50