Completed
Push — master ( 4c7da2...64af60 )
by Alex
02:34 queued 46s
created

Title::hasValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
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
     */
26 8
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
27
    {
28 8
        $node->setTitle($element->nodeValue);
29 8
    }
30
31
    /**
32
     * Tells if the node contains the expected value
33
     *
34
     * @param NodeInterface $node
35
     * @return bool
36
     */
37 7
    protected function hasValue(NodeInterface $node) : bool
38
    {
39 7
        return !! $node->getTitle();
40
    }
41
42
    /**
43
     * Creates and adds the element(s) to the docuement's rootElement
44
     *
45
     * @param \DomDocument $document
46
     * @param \DOMElement $rootElement
47
     * @param NodeInterface $node
48
     */
49 5
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
50
    {
51 5
        $title = htmlspecialchars($node->getTitle());
52 5
        $element = $document->createElement(static::NODE_NAME, $title);
53 5
        $rootElement->appendChild($element);
54 5
    }
55
}
56