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

Description::createElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php declare(strict_types=1);
2
/**
3
 * Created by PhpStorm.
4
 * User: alex
5
 * Date: 26/10/14
6
 * Time: 00:26
7
 */
8
namespace FeedIo\Rule;
9
10
use FeedIo\Feed\NodeInterface;
11
use FeedIo\RuleAbstract;
12
13
class Description extends RuleAbstract
14
{
15
    const NODE_NAME = 'description';
16
17
    /**
18
     * @param  NodeInterface $node
19
     * @param  \DOMElement   $element
20
     */
21 8
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
22
    {
23 8
        $string = '';
24 8
        if ($element->firstChild && $element->firstChild->nodeType == XML_CDATA_SECTION_NODE) {
25
            $string = $element->firstChild->textContent;
26
        } else {
27 8
            foreach ($element->childNodes as $childNode) {
28 8
                $string .= $element->ownerDocument->saveXML($childNode);
29
            }
30
        }
31
32 8
        $node->setDescription(htmlspecialchars_decode($string));
33 8
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 3
    protected function hasValue(NodeInterface $node) : bool
39
    {
40 3
        return !! $node->getDescription();
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 3
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
47
    {
48 3
        $description = htmlspecialchars($node->getDescription());
49
50 3
        $rootElement->appendChild($document->createElement($this->getNodeName(), $description));
51 3
    }
52
}
53