Completed
Push — project/php-7 ( 101bb9 )
by Alex
01:53
created

Description   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 39
ccs 10
cts 11
cp 0.9091
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createElement() 0 6 1
A setProperty() 0 15 4
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 8
    public function setProperty(NodeInterface $node, \DOMElement $element)
23
    {
24 8
        $string = '';
25 8
        if ($element->firstChild && $element->firstChild->nodeType == XML_CDATA_SECTION_NODE) {
26
            $string = $element->firstChild->textContent;
27
        } else {
28 8
            foreach ($element->childNodes as $childNode) {
29 8
                $string .= $element->ownerDocument->saveXML($childNode);
30
            }
31
        }
32
33 8
        $node->setDescription(htmlspecialchars_decode($string));
34
35 8
        return $this;
36
    }
37
38
    /**
39
     * creates the accurate DomElement content according to the $item's property
40
     *
41
     * @param  \DOMDocument  $document
42
     * @param  NodeInterface $node
43
     * @return \DOMElement
44
     */
45 3
    public function createElement(\DOMDocument $document, NodeInterface $node)
46
    {
47 3
        $description = htmlspecialchars($node->getDescription());
48
49 3
        return $document->createElement($this->getNodeName(), $description);
50
    }
51
}
52