Completed
Push — master ( 471a2c...9baf90 )
by Alex
14s
created

Description::setProperty()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 2
nop 2
crap 4
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 10
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
22
    {
23 10
        $string = '';
24 10
        if ($element->firstChild && $element->firstChild->nodeType == XML_CDATA_SECTION_NODE) {
25 2
            $string = $element->firstChild->textContent;
26
        } else {
27 10
            foreach ($element->childNodes as $childNode) {
28 10
                $string .= $element->ownerDocument->saveXML($childNode);
29
            }
30
        }
31
32 10
        $node->setDescription(htmlspecialchars_decode($string));
33 10
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 5
    protected function hasValue(NodeInterface $node) : bool
39
    {
40 5
        return !! $node->getDescription();
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 5
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
47
    {
48 5
        $description = htmlspecialchars($node->getDescription());
49
50 5
        $rootElement->appendChild($document->createElement($this->getNodeName(), $description));
51 5
    }
52
}
53