Logo::setProperty()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 4
nop 2
crap 5
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\Item;
14
use FeedIo\FeedInterface;
15
use FeedIo\Feed\NodeInterface;
16
use FeedIo\RuleAbstract;
17
18
class Logo extends RuleAbstract
19
{
20
    const NODE_NAME = 'image';
21
22
    protected $urlAttributeName = 'url';
23
24
    /**
25
     * @return string
26
     */
27 1
    public function getUrlAttributeName() : string
28
    {
29 1
        return $this->urlAttributeName;
30
    }
31
32
    /**
33
     * @param  string $name
34
     */
35
    public function setUrlAttributeName(string $name) : void
36
    {
37
        $this->urlAttributeName = $name;
38
    }
39
40
    /**
41
     * @param  NodeInterface $node
42
     * @param  \DOMElement   $element
43
     */
44 1
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
45
    {
46 1
        if ($node instanceof FeedInterface) {
47 1
            for ($i = $element->childNodes->length; --$i >= 0;) {
48 1
                $child = $element->childNodes->item($i);
49 1
                if ($child instanceof \DOMElement && $child->tagName === $this->getUrlAttributeName()) {
50 1
                    $node->setLogo($child->textContent);
51
                }
52
            }
53
        }
54 1
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59 2
    protected function hasValue(NodeInterface $node) : bool
60
    {
61 2
        return $node instanceof FeedInterface && !! $node->getLogo();
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67 1 View Code Duplication
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69 1
        if ($node instanceof FeedInterface) {
70 1
            $element = $document->createElement(static::NODE_NAME);
71 1
            $this->appendNonEmptyChild($document, $element, 'url', $node->getLogo());
72 1
            $this->appendNonEmptyChild($document, $element, 'title', $node->getTitle());
73 1
            $this->appendNonEmptyChild($document, $element, 'link', $node->getLink());
74
75 1
            $rootElement->appendChild($element);
76
        }
77 1
    }
78
}
79