Completed
Push — release/3.0 ( 106435...2e0212 )
by Alex
01:55
created

Language::setProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
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\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
     * @return $this
25
     */
26 1
    public function setProperty(NodeInterface $node, \DOMElement $element)
27
    {
28 1
        if ($node instanceof FeedInterface) {
29 1
            $node->set(static::NODE_NAME, $element->nodeValue);
30 1
        }
31
32 1
        return $this;
33
    }
34
35
    /**
36
     * creates the accurate DomElement content according to the $item's property
37
     *
38
     * @param  \DomDocument  $document
39
     * @param  NodeInterface $node
40
     * @return \DomElement
41
     */
42 2
    public function createElement(\DomDocument $document, NodeInterface $node)
43
    {
44 2
        if (!($node instanceof FeedInterface) || is_null($node->getLanguage())) {
45 1
            return;
46
        }
47
48 2
        return $document->createElement($this->getNodeName(), $node->getLanguage());
49
    }
50
}
51