Language::addElement()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
cc 3
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 View Code Duplication
class Language extends RuleAbstract
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 5
    protected function hasValue(NodeInterface $node) : bool
36
    {
37 5
        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