RevisionNode::asRevision()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Queryr\DumpReader\XmlReader;
4
5
use DOMNode;
6
use Queryr\DumpReader\Revision;
7
use XMLReader;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class RevisionNode {
14
15
	private $id;
16
	private $model;
17
	private $format;
18
	private $text;
19
	private $timeStamp;
20
21
	public function __construct( DOMNode $pageNode ) {
22
		foreach ( $pageNode->childNodes as $childNode ) {
23
			$this->handleNode( $childNode );
24
		}
25
	}
26
27
	private function handleNode( DOMNode $node ) {
28
		if ( $this->hasElementName( $node, 'id' ) ) {
29
			$this->id = $node->textContent;
30
		}
31
32
		if ( $this->hasElementName( $node, 'model' ) ) {
33
			$this->model = $node->textContent;
34
		}
35
36
		if ( $this->hasElementName( $node, 'format' ) ) {
37
			$this->format = $node->textContent;
38
		}
39
40
		if ( $this->hasElementName( $node, 'text' ) ) {
41
			$this->text = $node->textContent;
42
		}
43
44
		if ( $this->hasElementName( $node, 'timestamp' ) ) {
45
			$this->timeStamp = $node->textContent;
46
		}
47
	}
48
49
	private function hasElementName( DOMNode $node, $name ) {
50
		return $node->nodeType === XMLReader::ELEMENT && $node->nodeName === $name;
51
	}
52
53
	public function asRevision() {
54
		return new Revision(
55
			$this->id,
56
			$this->model,
57
			$this->format,
58
			$this->text,
59
			$this->timeStamp
60
		);
61
	}
62
63
}