Completed
Pull Request — project/php-7 (#133)
by Alex
04:04 queued 01:49
created

ModifiedSince::hasValue()   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
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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\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
     * @return $this
24
     */
25 7
    public function setProperty(NodeInterface $node, \DOMElement $element)
26
    {
27 7
        $node->setLastModified($this->getDateTimeBuilder()->convertToDateTime($element->nodeValue));
28
29 7
        return $this;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 4
    protected function hasValue(NodeInterface $node) : bool
36
    {
37 4
        return true;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 4
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
44
    {
45 4
        $date = is_null($node->getLastModified()) ? new \DateTime():$node->getLastModified();
46
47 4
        $rootElement->appendChild($document->createElement(
48 4
            $this->getNodeName(),
49 4
            $date->format($this->getDefaultFormat())
50
        ));
51 4
    }
52
}
53