Completed
Push — issue/184 ( 870e36 )
by Alex
02:01
created

Category   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 45
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 9 1
A createCategoryElement() 0 9 1
A setNonEmptyAttribute() 0 6 2
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\Atom;
12
13
use FeedIo\Feed\Node\CategoryInterface;
14
use FeedIo\Feed\NodeInterface;
15
16
class Category extends \FeedIo\Rule\Category
17
{
18
19
    /**
20
     * @param  NodeInterface $node
21
     * @param  \DOMElement   $element
22
     */
23 3
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
24
    {
25 3
        $category = $node->newCategory();
26 3
        $category->setScheme($this->getAttributeValue($element, 'scheme'))
27 3
        ->setLabel($this->getAttributeValue($element, 'label'))
28 3
        ->setTerm($this->getAttributeValue($element, 'term'));
29
30 3
        $node->addCategory($category);
31 3
    }
32
33
    /**
34
     * @param  \DomDocument   $document
35
     * @param  CategoryInterface $category
36
     * @return \DomElement
37
     */
38 3
    public function createCategoryElement(\DomDocument $document, CategoryInterface $category) : \DOMElement
39
    {
40 3
        $element = $document->createElement($this->getNodeName());
41 3
        $this->setNonEmptyAttribute($element, 'scheme', $category->getScheme());
42 3
        $this->setNonEmptyAttribute($element, 'term', $category->getTerm());
43 3
        $this->setNonEmptyAttribute($element, 'label', $category->getLabel());
44
45 3
        return $element;
46
    }
47
48
    /**
49
     * Sets the attribute only if the value is not emtpy
50
     * @param DomElement $element
51
     * @param string     $name
52
     * @param [type]     $value
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
53
     */
54 3
    protected function setNonEmptyAttribute(\DomElement $element, string $name, string $value = null) : void
55
    {
56 3
        if (! is_null($value) ) {
57 3
            $element->setAttribute($name, $value);
58
        }
59 3
    }
60
}
61