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

Description   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 40
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasValue() 0 4 1
A addElement() 0 6 1
A setProperty() 0 13 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