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

ModifiedSince   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 4 1
A hasValue() 0 4 1
A addElement() 0 9 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