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

Title   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 43
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 6 1
A hasValue() 0 4 1
A addElement() 0 6 1
1
<?php
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Rule;
12
13
use FeedIo\Feed\NodeInterface;
14
use FeedIo\RuleAbstract;
15
16
class Title extends RuleAbstract
17
{
18
    const NODE_NAME = 'title';
19
20
    /**
21
     * Sets the accurate $item property according to the DomElement content
22
     *
23
     * @param  NodeInterface $node
24
     * @param  \DOMElement   $element
25
     * @return $this
26
     */
27 7
    public function setProperty(NodeInterface $node, \DOMElement $element)
28
    {
29 7
        $node->setTitle($element->nodeValue);
30
31 7
        return $this;
32
    }
33
34
    /**
35
     * Tells if the node contains the expected value
36
     *
37
     * @param NodeInterface $node
38
     * @return bool
39
     */
40 7
    protected function hasValue(NodeInterface $node) : bool
41
    {
42 7
        return !! $node->getTitle();
43
    }
44
45
    /**
46
     * Creates and adds the element(s) to the docuement's rootElement
47
     *
48
     * @param \DomDocument $document
49
     * @param \DOMElement $rootElement
50
     * @param NodeInterface $node
51
     */
52 5
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
53
    {
54 5
        $title = htmlspecialchars($node->getTitle());
55 5
        $element = $document->createElement(static::NODE_NAME, $title);
56 5
        $rootElement->appendChild($element);
57 5
    }
58
}
59