Completed
Push — issue/98 ( 297abd )
by Alex
03:51 queued 03:51
created

RuleAbstract   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 72
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A getNodeName() 0 4 1
A getAttributeValue() 0 8 2
setProperty() 0 1 ?
createElement() 0 1 ?
A getChildValue() 0 9 2
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;
12
13
use FeedIo\Feed\NodeInterface;
14
15
abstract class RuleAbstract
16
{
17
    const NODE_NAME = 'node';
18
19
    /**
20
     * @var string
21
     */
22
    protected $nodeName;
23
24
    /**
25
     * @param string $nodeName
26
     */
27 92
    public function __construct($nodeName = null)
28
    {
29 92
        $this->nodeName = is_null($nodeName) ? static::NODE_NAME : $nodeName;
30 92
    }
31
32
    /**
33
     * @return string
34
     */
35 53
    public function getNodeName()
36
    {
37 53
        return $this->nodeName;
38
    }
39
40
    /**
41
     * @param  \DOMElement $element
42
     * @param  string      $name
43
     * @return string|null
44
     */
45 9
    public function getAttributeValue(\DOMElement $element, $name)
46
    {
47 9
        if ($element->hasAttribute($name)) {
48 8
            return $element->getAttribute($name);
49
        }
50
51 3
        return;
52
    }
53
54
    /**
55
     * @param  \DOMElement $element
56
     * @param  string      $name
57
     * @return string|null
58
     */
59 4
    public function getChildValue(\DOMElement $element, $name)
60
    {
61 4
        $list = $element->getElementsByTagName($name);
62 4
        if ( $list->length > 0 ) {
63 3
            return $list->item(0)->nodeValue;
64
        }
65
66 1
        return;
67
    }
68
69
    /**
70
     * Sets the accurate $item property according to the DomElement content
71
     *
72
     * @param  NodeInterface $node
73
     * @param  \DOMElement   $element
74
     * @return mixed
75
     */
76
    abstract public function setProperty(NodeInterface $node, \DOMElement $element);
77
78
    /**
79
     * creates the accurate DomElement content according to the $item's property
80
     *
81
     * @param  \DomDocument  $document
82
     * @param  NodeInterface $node
83
     * @return \DomElement
84
     */
85
    abstract public function createElement(\DomDocument $document, NodeInterface $node);
86
}
87