Completed
Pull Request — project/php-7 (#133)
by Alex
04:04 queued 01:49
created

Description::setProperty()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

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