Completed
Push — issue/161 ( d32a7d )
by Alex
01:56
created

Description   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 76.47%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 44
ccs 13
cts 17
cp 0.7647
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 15 4
A createElement() 0 11 3
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 9
    public function setProperty(NodeInterface $node, \DOMElement $element)
23
    {
24 9
        $string = '';
25 9
        if ($element->firstChild && $element->firstChild->nodeType == XML_CDATA_SECTION_NODE) {
26
            $string = $element->firstChild->textContent;
27
        } else {
28 9
            foreach ($element->childNodes as $childNode) {
29 9
                $string .= $element->ownerDocument->saveXML($childNode);
30 9
            }
31
        }
32
33 9
        $node->setDescription(htmlspecialchars_decode($string));
34
35 9
        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 3
        $element = $document->createElement($this->getNodeName(), $description);
49
50 3
        if ($description !== $node->getDescription() && $this->getNodeName() != 'description') {
51
            $element->setAttribute('type', 'html');
52
        }
53
54 3
        return $element;
55
    }
56
}
57