Completed
Push — master ( d16017...97f55f )
by Alex
9s
created

Language::addElement()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 3
crap 3.072
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\FeedInterface;
15
use FeedIo\RuleAbstract;
16
17
class Language extends RuleAbstract
18
{
19
    const NODE_NAME = 'language';
20
21
    /**
22
     * @param  NodeInterface $node
23
     * @param  \DOMElement   $element
24
     */
25 3
    public function setProperty(NodeInterface $node, \DOMElement $element): void
26
    {
27 3
        if ($node instanceof FeedInterface) {
28 3
            $node->set(static::NODE_NAME, $element->nodeValue);
29
        }
30 3
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 4
    protected function hasValue(NodeInterface $node) : bool
36
    {
37 4
        return $node instanceof FeedInterface && !! $node->getLanguage();
38
    }
39
40
    /**
41
     * creates the accurate DomElement content according to the $item's property
42
     *
43
     * @param  \DomDocument  $document
44
     * @param  NodeInterface $node
45
     */
46 2
    public function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node): void
47
    {
48 2
        if (!($node instanceof FeedInterface) || is_null($node->getLanguage())) {
49
            return;
50
        }
51 2
        $rootElement->appendChild($document->createElement($this->getNodeName(), $node->getLanguage()));
52 2
    }
53
}
54